I developed a VBA code that can fill column B when column A is filled, at first the VBA code runs fast but when the number of cells filled is large the VBA code becomes very slow, how can I make the code run more efficiently so that it is no longer slow? I also want to make the code run automatically without having to create a shortcut to run the macro, so that every time new data is inputted in column A, column B will be filled in automatically. Here is my code
Sub CodeMaster_PipingTagSection()
Dim lastrow As Long
Dim i As Long
lastrow = ActiveSheet.Range("I" & Rows.Count).End(xlUp).Row
For i = 7 To lastrow
If Not IsEmpty(Cells(i, 9)) Then
Cells(i, 6) = "TEMPERATE"
Cells(i, 11) = Split(Cells(i, 9), "-")(UBound(Split(Cells(i, 9), "-")))
Cells(i, 34) = "Three_Layer_PE_or_PP"
Cells(i, 38) = "N"
Cells(i, 41) = "N"
Cells(i, 45) = "Review by Process SME"
Cells(i, 54) = "False"
Cells(i, 55) = "1"
Cells(i, 56) = "N"
Cells(i, 70) = "Piping"
Cells(i, 71) = "PIPE"
Cells(i, 75) = "Criticality RBI Component - Piping"
Cells(i, 76) = "Non Intrusive"
Cells(i, 83) = "True"
Cells(i, 84) = "True"
Cells(i, 85) = "N"
Cells(i, 87) = "N"
Cells(i, 88) = "N"
Cells(i, 89) = "Visual Detection"
Cells(i, 90) = "Manual Shutdown"
Cells(i, 91) = "Inventory blowdown"
Cells(i, 96) = "100"
Cells(i, 98) = "False"
Cells(i, 102) = "False"
ElseIf IsEmpty(Cells(i, 9)) Then
Cells(i, 6).ClearContents
Cells(i, 11).ClearContents
Cells(i, 34).ClearContents
Cells(i, 38).ClearContents
Cells(i, 41).ClearContents
Cells(i, 45).ClearContents
Cells(i, 54).ClearContents
Cells(i, 55).ClearContents
Cells(i, 56).ClearContents
Cells(i, 70).ClearContents
Cells(i, 71).ClearContents
Cells(i, 75).ClearContents
Cells(i, 76).ClearContents
Cells(i, 83).ClearContents
Cells(i, 84).ClearContents
Cells(i, 85).ClearContents
Cells(i, 87).ClearContents
Cells(i, 88).ClearContents
Cells(i, 89).ClearContents
Cells(i, 90).ClearContents
Cells(i, 91).ClearContents
Cells(i, 96).ClearContents
Cells(i, 98).ClearContents
Cells(i, 102).ClearContents
End If
Next i
End Sub
to speed up the code I have tried turning off screen updating by input this code
Sub Stop_Events()
Application.EnableEvents = False
'...Statemets
Application.EnableEvents = True
End Sub
but it still running slow, I need another ways to make this VBA running fast and automatically