VBA: Execute code on sheet names with 4 characters

sachavez

Active Member
Any way to get the code to work on sheet names with only 4 characters?

Code:
    Cells.Find(What:="IG").EntireRow.Delete
    Cells.Find(What:="OG").EntireRow.Delete
    
    With ActiveSheet.UsedRange
        .AutoFilter Field:=13, Operator:=xlFilterNoFill
        .Offset(1).SpecialCells(xlVisible).EntireRow.Delete
        .AutoFilter
    End With
    
    ActiveSheet.UsedRange.RemoveDuplicates Columns:=13, Header:=xlYes
 

Fluff

MrExcel MVP, Moderator
How about
Code:
Sub sachavez2()
   Dim Ws As Worksheet
   
   For Each Ws In Worksheets
      If Len(Ws.Name) = 4 Then
         Ws.Cells.Find(What:="IG").EntireRow.Delete
         Ws.Cells.Find(What:="OG").EntireRow.Delete
    
         With Ws.UsedRange
             .AutoFilter Field:=13, Operator:=xlFilterNoFill
             .Offset(1).SpecialCells(xlVisible).EntireRow.Delete
             .AutoFilter
         End With
         
         Ws.UsedRange.RemoveDuplicates Columns:=13, Header:=xlYes
      End If
   Next Ws
End Sub
 

sachavez

Active Member
Perfect, thank you!

Appreciate all of the help today. This project is complete, and now I have a few more tools in the toolbox.

Steve

How about
Code:
Sub sachavez2()
   Dim Ws As Worksheet
   
   For Each Ws In Worksheets
      If Len(Ws.Name) = 4 Then
         Ws.Cells.Find(What:="IG").EntireRow.Delete
         Ws.Cells.Find(What:="OG").EntireRow.Delete
    
         With Ws.UsedRange
             .AutoFilter Field:=13, Operator:=xlFilterNoFill
             .Offset(1).SpecialCells(xlVisible).EntireRow.Delete
             .AutoFilter
         End With
         
         Ws.UsedRange.RemoveDuplicates Columns:=13, Header:=xlYes
      End If
   Next Ws
End Sub
 

Some videos you may like

This Week's Hot Topics

Top