Can I use "Case" instead of this repeating macro?
Posted by Nils on May 25, 2000 8:08 AM
I recorded a macro to change a field from date "2000/01 to Jan" and I copied it for the rest of the months. Its a long and cumbersome macro with a lot of repeats, so I thought I could use Case instead, but I'm not sure how I would set it up. (I'm beginner Excel macro's / VB). If Case can not be used can I use an "If" statement?
Thanks for any help.
Sub ReplaceMonth()
'
' ReplaceMonth Macro
' Macro recorded 3/27/00 by Nils Christensen
'
Selection.CurrentRegion.Select
Selection.Sort Key1:=Range("B2"), _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom
' quarter 1
' Jan
Cells.Replace What:="????/01", _
Replacement:="Jan", _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False
' Feb
Cells.Replace What:="????/02", _
Replacement:="Feb", _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False
' Mar
Cells.Replace What:="????/03", _
Replacement:="Mar", _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False
End Sub
Thank you