Avatar of Euro5
Euro5
Flag 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

VBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Alex [***Alex140181***]

8/22/2022 - Mon