VBA: Execute code on sheet names with 4 characters
Results 1 to 4 of 4

Thread: VBA: Execute code on sheet names with 4 characters
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    May 2009
    Location
    Fort Worth, TX
    Posts
    436
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow VBA: Execute code on sheet names with 4 characters

    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
    -Steve

    Committed to learning VBA!
    MS Excel 2007 - Windows XP
    MS Excel 2004 - Mac OS X

  2. #2
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    25,638
    Post Thanks / Like
    Mentioned
    445 Post(s)
    Tagged
    45 Thread(s)

    Default Re: VBA: Execute code on sheet names with 4 characters

    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
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  3. #3
    Board Regular
    Join Date
    May 2009
    Location
    Fort Worth, TX
    Posts
    436
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA: Execute code on sheet names with 4 characters

    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

    Quote Originally Posted by Fluff View Post
    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
    -Steve

    Committed to learning VBA!
    MS Excel 2007 - Windows XP
    MS Excel 2004 - Mac OS X

  4. #4
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    25,638
    Post Thanks / Like
    Mentioned
    445 Post(s)
    Tagged
    45 Thread(s)

    Default Re: VBA: Execute code on sheet names with 4 characters

    Glad to help & thanks for the feedback
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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