Consulting

Results 1 to 3 of 3

Thread: Solved: Find & Replace Macro replacing outside of defined area

  1. #1
    VBAX Tutor
    Joined
    Jan 2006
    Posts
    248
    Location

    Solved: Find & Replace Macro replacing outside of defined area

    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

    [VBA]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
    [/VBA]

  2. #2
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    Instead of Cells.Replace, it should be Selection.Replace

  3. #3
    VBAX Tutor
    Joined
    Jan 2006
    Posts
    248
    Location
    Thanks, JKwan thats has solved that problem, I will mark as solved, thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •