+ Reply to Thread
Results 1 to 5 of 5

macro to select worksheet based on tab color

Hybrid View

  1. #1
    Registered User
    Join Date
    02-01-2012
    Location
    ny
    MS-Off Ver
    Excel 2003
    Posts
    8

    macro to select worksheet based on tab color

    Hi can anyone help me create a macro that selects all worksheet tabs of a particular color. For instance, if i am selecting a worksheet that the tab is colored red, what is the vba code to select all red tabs in the workbook?

  2. #2
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,028

    Re: macro to select worksheet based on tab color

    just try...
    Sub Button1_Click()
     Dim ws As Worksheet
         
        For Each ws In Worksheets
            If ws.Tab.Color = vbRed Then ws.Visible = xlSheetHidden
        Next ws
    End Sub
    and
    Sub Button2_Click()
    Dim ws As Worksheet
         
        For Each ws In Worksheets
            If ws.Tab.Color = vbRed Then ws.Visible = xlSheetVisible
        Next ws
    End Sub
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  3. #3
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: macro to select worksheet based on tab color

    replace the number with your own color number

    Sub Macro2()
    Dim ws As Worksheet
    
    
    For Each ws In ThisWorkbook.Worksheets
        If ws.Tab.Color = 192 Then
        ws.Select (False)
        End If
    Next ws
      
    End Sub
    You can find out about the tab color by using
    msgbox activesheet.tab.color

  4. #4
    Registered User
    Join Date
    02-01-2012
    Location
    ny
    MS-Off Ver
    Excel 2003
    Posts
    8
    What if I want the macro to be written so that if I click on a tab of any color all tabs of that color.in the workbook are selected. Thx for ur help:D

  5. #5
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: macro to select worksheet based on tab color

    In that case put this in your workbook module. I use a conditional check box to turn on/off macro. In my case, if worksheet macro on and off range A1 = True then macro is active, if A1= False then macro is inactive.

    Anyone know why I am having issue with checkbox active x control? If I use checkbox as a conditional check if won't let me go into Design mode unless I select other tab first.

    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    If Worksheets("Turn on off macro").Cells(1, 1) = True Then
    Call Test
    End If
    
    End Sub
    
    Sub Test()
    Dim Ws As Worksheet
    
    For Each Ws In ThisWorkbook.Worksheets
        If Ws.Tab.Color = ActiveSheet.Tab.Color Then
        Ws.Select (False)
        End If
    Next Ws
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1