vba select 2 or more color tab at once

kelvin_9

Active Member
Joined
Mar 6, 2015
Messages
444
Office Version
  1. 2019
Hello All,

i'm wondering how could i select more than 1 color tab at once, i can only select one at a time
ps. i use color index 7 & color index 8
thanks for your guidance

VBA Code:
Sub Macro1()
'
' Macro1 Macro
'

'

Dim ws As Worksheet
Dim strg() As String
Dim count As Integer
count = 1
 
    For Each ws In Worksheets
        If ws.Tab.ColorIndex = 8 And Not ws.CodeName = "Sheet1" Then
            ReDim Preserve strg(count) As String
            strg(count) = ws.Name
            count = count + 1
        Else
        End If
    Next ws
    
    Sheets(strg(1)).Select
    For i = 2 To UBound(strg)
        Sheets(strg(i)).Select False
    Next i

End Sub
 
It needs to go directly after the loop & before the ReDim
Fulff
i got you now, thank you very much

Code:
Sub kelvin()
Dim ws As Worksheet
Dim strg() As String
Dim count As Integer

ReDim strg(1 To Worksheets.count)
    For Each ws In Worksheets
        If (ws.Tab.ColorIndex = 7 Or ws.Tab.ColorIndex = 8) And Not ws.CodeName = "Sheet1" Then
            count = count + 1
            strg(count) = ws.Name
        Else
        End If
    Next ws
    
    If count = 0 Then
      MsgBox "No tabs"
      Exit Sub
    End If

    ReDim Preserve strg(1 To count)
    Sheets(strg).Select

End Sub
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top