Nice and simple
Sub test()
Dim strVariable As String
Dim nTime As Double
Dim i As Long
nTime = Timer
For i = 1 To 100000000
If Len(strVariable) > 0 Then
'Using 100,000,000 Loops - Time: 1.418 seconds
End If
Next i
Debug.Print Timer - nTime
nTime = Timer
For i = 1 To 100000000
If strVariable <> "" Then
'Using 100,000,000 Loops - Time: 3.18 seconds
End If
Next i
Debug.Print Timer - nTime
nTime = Timer
For i = 1 To 100000000
If strVariable <> vbNullString Then
'Using 100,000,000 Loops - Time: 3.105 seconds
End If
Next i
Debug.Print Timer - nTime
End Sub
Sub ReplaceText()
Dim vecBefore As Variant
Dim vecAfter As Variant
Dim lastrow As Long
Dim pos As Long
Dim i As Long, j As Long
Application.ScreenUpdating = False
With Worksheets("Sheet2")
vecBefore = Application.Transpose(.Range(.Range("A1"), .Range("A1").End(xlDown)))
vecAfter = Application.Transpose(.Range(.Range("B1"), .Range("B1").End(xlDown)))
End With
With Worksheets("Sheet1")
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To lastrow
For j = LBound(vecBefore) To UBound(vecBefore)
pos = InStr(.Cells(i, "A").Value, vecBefore(j))
If pos > 1 Then
.Cells(i, "A").Value = Replace(.Cells(i, "A").Value, vecBefore(j), vecAfter(j))
End If
Next j
Next i
End With
Application.ScreenUpdating = True
End Sub
Bookmarks