If Statement Assessing Worksheet Tab Color

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am trying to create an if statement that will execute code if a particular worksheet tab is any color other than red.
I have tried this ...
Code:
If Worksheets("Master").Tab.color <> vbRed Then

but is errs with a "Subscript out of range" error with that line though.

The worksheet "Master" exists in the active workbook. It's tab is not red, so the code following the if statement should be execute.

Please help?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I am trying to create an if statement that will execute code if a particular worksheet tab is any color other than red.
I have tried this ...
Code:
If Worksheets("Master").Tab.color <> vbRed Then

but is errs with a "Subscript out of range" error with that line though.

The worksheet "Master" exists in the active workbook. It's tab is not red, so the code following the if statement should be execute.

Please help?

not tested tho.

try :
Code:
Sub test()

Dim tsh As Worksheet
Dim tCol As String


Set tsh = ActiveWorkbook.Sheets("Master")
tCol = vbred


    If tsh.Tab.Color <> tCol Then
        With tsh
            .Tab.Color = tCol
        End With
    End If
    
End Sub
 
Last edited:
Upvote 0
Hello ttray33y,

My apologies for taking so long to acknowledge your help. Only now have I gotten around to work on this issue.
I do appreciate the effort! Unfortunately, I still get the same error at the same point with your code. Other than setting the worksheet object and the vbcolor to variables I see little difference to what I had originally used.

I'm still searching for a solution ... anyone?

Here is some code ... ttray's contribution in purple, my original in blue.
Rich (BB code):
ws_name = "WS " & format(ws_vh.Range("B17"), "dd-mmm-yy") & ".xlsx"
        If Dir(path_name & ws_name) <> "" Then '.tglb_wpl_crtt.BackColor = RGB(0,153,211)
            Workbooks.Open (path_name & ws_name)
            Set wb_name = Workbooks(ws_name)
            wb_name.Windows(1).Visible = False
            bt = 0
            With wb_name
                tCol = vbRed
                If Worksheets("Master").Tab.color <> tCol Then  '<--- Subscript out of range.
                    .tglb_master.Enabled = True
                    .tglb_master.BackColor = RGB(0, 153, 211)
                    bt = bt + 1
                End If
                
                If Worksheets("CUE").Tab.color <> vbRed Then '<--- Subscript out of range.
                    .tglb_cue_ws.Enabled = True
                    .tglb_cue_ws.BackColor = RGB(0, 153, 211)
                    bt = bt + 1
                End If
      ...
 
Upvote 0
I suspect that you are missing a . from infront of the worksheet ie
Code:
If [COLOR=#ff0000].[/COLOR]Worksheets("CUE").Tab.color <> vbRed Then
Also you have a lower case c on color is that in your actual macro?
Because it would normally be converted to an upper case C
 
Last edited:
Upvote 0
Hello Fluff ...
That was a correct suspicion! The period solved the problem indeed.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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