So the values in column C are text and you want to keep them as text?
You don't want to change it to numbers and just use formatting to show the
leading 0's?
Even if you do this change manually, excel sees it as a number (not as Text).
One way around this is to cycle though all the cells and do the replacements
that way. But I gotta believe that would be slower than the mass changes.
So how about this...
The macro inserts a new column D.
Takes the value in column C and puts it in column D, but with a prefix character
(I used char(1)--very rarely found in a worksheet).
Then do all the changes to column D and strip that prefix character out of
column D and plop it back into column C.
It worked fine in my simple testing--but try it against a copy of your workbook
(or close without saving if it's wrong!).
Option Explicit
Sub testme()
Dim curWks As Worksheet
Dim myCell As Range
Dim myFromRng As Range
Dim myRngToChange As Range
Dim LastRowInColC As Long
Dim CalcMode As Long
Application.ScreenUpdating = False
CalcMode = Application.Calculation
Set curWks = Worksheets("Sheet1")
With curWks
Set myFromRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
.Range("d1").EntireColumn.Insert
LastRowInColC = .Cells(.Rows.Count, "C").End(xlUp).Row
Set myRngToChange = .Range("d1:d" & LastRowInColC)
With myRngToChange
.NumberFormat = "General"
.Formula = "=char(1)&c1"
.Value = .Value
End With
Application.Calculation = xlCalculationManual
For Each myCell In myFromRng.Cells
Application.StatusBar = "Processing #: " & myCell.Row _
& " of: " & myRngToChange.Cells.Count & " at: " & Now
myRngToChange.Cells.Replace what:=myCell.Value, _
replacement:=myCell.Offset(0, 1).Value, _
lookat:=xlPart, MatchCase:=False, _
searchorder:=xlByRows
Next myCell
Application.Calculation = CalcMode
Application.StatusBar = False
With .Range("c1:c" & LastRowInColC)
.NumberFormat = "General"
.Formula = "=mid(d1,2,1000)"
.NumberFormat = "@"
.Value = .Value
End With
.Range("D1").EntireColumn.Delete
End With
Application.ScreenUpdating = True
End Sub
And I don't know why it's locking up for you. Maybe if we turn calculation off
and do the changes, then toggle it back on, it would speed it up (maybe it
wasn't done--not really locked up.)
Since this turns calculation off, you'll have to change it back to what you had
(tools|options|calculation tab) if you interrupt it.