I am using the below VBA code for 88K lines. Due to the number of lines, it is moving very slow. It is supposed to determine if there is a zero beginning in cell D17 and place the message “OK – No Differences” in the next cell. How do you suggest speeding this up? See code below.
Sub Addtext()
Dim lrow As Long, cell As Range
lrow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "D").End(xlUp).Row
For Each cell In Range("D17:D" & lrow)
If cell.Value = 0 Then
cell.Offset(0, 1) = "OK - No Differences"
End If
Next cell
Application.screen = False
End Sub
Sub AddtextOptimized()
Dim lrow As Long, i As Long
Dim data As Variant
Application.ScreenUpdating = False
lrow = Cells(Rows.Count, "D").End(xlUp).Row
data = Range("D17:D" & lrow).Value
For i = 1 To UBound(data, 1)
If data(i, 1) = 0 Then
Cells(i + 16, 5).Value = "OK - No Differences"
End If
Next i
Application.ScreenUpdating = True
End Sub
New contributor
Krutarth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2