PDA

View Full Version : Solved: Find & Replace Macro replacing outside of defined area



Barryj
05-13-2011, 10:43 AM
I have recorded the following macro to replace the letter L & W in the defined columns and rows, but it is also replacing the letter L & W in column A, how can I stop it from replacing outside the defined columns and rows in the macro.


Thanks

Private Sub CommandButton1_Click()
Range("$B$1:$G$28").Select
Cells.Replace What:="W", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

Range("$B$1:$G$28").Select
Cells.Replace What:="L", Replacement:="", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End Sub

JKwan
05-13-2011, 10:50 AM
Instead of Cells.Replace, it should be Selection.Replace

Barryj
05-13-2011, 10:54 AM
Thanks, JKwan thats has solved that problem, I will mark as solved, thanks again.