Link to home
Start Free TrialLog in
Avatar of Euro5
Euro5Flag for United States of America

asked on

vba replace clearing on all sheets

I have this wonderful VBA cold that removes the row when it finds the phrase.
BUT I find that I have a tab that I don't want it to run on, but this code runs through all the worksheets. Is there any way to say "Run on all worksheets EXCEPT this one?"
The tab "Mapping" is the one I need to exclude. THANK YOU!!
Sub ReplaceTotal()

Dim rDelete As Range
Dim strSearch As String
Dim iLookAt As Long
Dim bMatchCase As Boolean
Dim ws As Worksheet


strSearch = "Total"    'Value to search for inbetween ""


iLookAt = xlPart 'Change to xlWhole if the entire cell must equal search string
bMatchCase = False  'Change to True if you want search to be case sensitive


Set rDelete = Nothing


Application.ScreenUpdating = False


For Each ws In Worksheets
With ws.UsedRange
    Set rFind = .Find(strSearch, LookIn:=xlValues, LookAt:=iLookAt, SearchDirection:=xlPrevious, MatchCase:=bMatchCase)
    If Not rFind Is Nothing Then
        Do
            Set rDelete = rFind
            Set rFind = .FindPrevious(rFind)
            If rFind.Address = rDelete.Address Then Set rFind = Nothing
            rDelete.EntireRow.Delete
        Loop While Not rFind Is Nothing
    End If
End With
Next
Application.ScreenUpdating = True
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Alex [***Alex140181***]
Alex [***Alex140181***]
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial