Just because I had some spare time!!!!!
On 518,400 cells on my older XP machine:
6.23 seconds
Sub Replace_With_An_Array()
Dim Rng As Range
Dim What As Variant
Dim Repl As Variant
Dim t
Dim x
Dim i As Long
t = Timer
Application.ScreenUpdating = False
What = Array(1, 2, 3, 4, 5)
Repl = Array("A", "B", "C", "D", "E")
For i = 0 To UBound(What)
Set Rng = ActiveSheet.Range("E2", Range("E" & Rows.Count).End(xlUp))
Rng.Replace What:=What(i), replacement:=Repl(i), MatchCase:=False
Next i
Application.ScreenUpdating = True
MsgBox "This macro took " & Format(Round(Timer - t, 2), "00:00:00.00") & " seconds to run."
End Sub
6.22 seconds
Sub Maybe_This_A()
Dim r As Range
Dim t
Dim x
t = Timer
Application.ScreenUpdating = False
Set r = ActiveSheet.Range("E2", Range("E" & Rows.Count).End(xlUp))
r.Replace What:=1, lookat:=xlPart, replacement:="A"
r.Replace What:=2, lookat:=xlPart, replacement:="B"
r.Replace What:=3, lookat:=xlPart, replacement:="C"
r.Replace What:=4, lookat:=xlPart, replacement:="D"
r.Replace What:=5, lookat:=xlPart, replacement:="E"
Application.ScreenUpdating = True
MsgBox "This macro took " & Format(Round(Timer - t, 2), "00:00:00.00") & " seconds to run."
End Sub
16.39 seconds
Sub Replace_Some()
Dim c As Range
Dim t
Dim x
t = Timer
Application.ScreenUpdating = False
For Each c In Range("E2", Range("E" & Rows.Count).End(xlUp))
If c.Value = 1 Then
c.Value = "A"
ElseIf c.Value = 2 Then c.Value = "B"
ElseIf c.Value = 3 Then c.Value = "C"
ElseIf c.Value = 4 Then c.Value = "D"
ElseIf c.Value = 5 Then c.Value = "E"
End If
Next c
Application.ScreenUpdating = True
MsgBox "This macro took " & Format(Round(Timer - t, 2), "00:00:00.00") & " seconds to run."
End Sub
6.28 seconds
Sub tgr()
Dim t
Dim x
t = Timer
Application.ScreenUpdating = False
With Intersect(ActiveSheet.UsedRange, Columns("E"))
.Replace "1", "A"
.Replace "2", "B"
.Replace "3", "C"
.Replace "4", "D"
.Replace "5", "E"
End With
Application.ScreenUpdating = True
MsgBox "This macro took " & Format(Round(Timer - t, 2), "00:00:00.00") & " seconds to run."
End Sub
Bookmarks