Question : Excel 2003 Macro to change values in a column

I would like a macro that will travel down column E and change values as per the following:

If cell contains any single digit number from 0-9 (inclusive) - add prefix of "200"
(e.g. if cell contains "3", change to "2003").

If cell contains "10" - add prefix of "20"
(e.g. if cell contains "10", change to "2010")

If cell contains any two digit number - add prefix of "19"
(e.g. if cell contains "97", change to "1997")

Answer : Excel 2003 Macro to change values in a column

actually this is more robust:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
Sub colE()
Dim rngstr As String
Dim Estr As String
rngstr = ActiveSheet.UsedRange.AddressLocal
 
 
rngstr = Mid(rngstr, InStr(1, rngstr, ":") + 1)
rngstr = Mid(rngstr, InStr(1, rngstr, "$") + 1)
rngstr = Mid(rngstr, InStr(1, rngstr, "$") + 1)
MsgBox rngstr
 
Estr = "E1:E" & rngstr
Range(Estr).Select
For Each cell In Selection
cell.Activate
    If cell.Value <> "" Then
If Len(CStr(cell.Value)) = 1 Then cell.Value = 2000 + cell.Value
 
If cell.Value = 10 Then cell.Value = 2000 + cell.Value
If Len(CStr(cell.Value)) = 2 Then cell.Value = 1900 + cell.Value
 
    End If
Next
End Sub
Open in New Window Select All
Random Solutions  
 
programming4us programming4us