change color of tab macro

rki1966

Active Member
Joined
Feb 1, 2004
Messages
351
I want a macro that will change the color of all tabs within the workbook to one color.

The formula gives me errors:

Sub Color2()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Activate
With Selection.Tab
.ColorIndex = 6
End With

Next ws
End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi there,

This works for me ..

<font face=Tahoma New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN>

<SPAN style="color:#00007F">Sub</SPAN> Color3()
    <SPAN style="color:#00007F">Dim</SPAN> ws <SPAN style="color:#00007F">As</SPAN> Worksheet
    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> ws <SPAN style="color:#00007F">In</SPAN> Worksheets
        ws.Tab.ColorIndex = 6
    <SPAN style="color:#00007F">Next</SPAN> ws
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

It's not working for you because the Selection object is for a range, not a worksheet. The range object doesn't have a Tab property.
 
Upvote 0
You can also do it directly or with conditional logic:

Sub tabColorToggle()

If ActiveWorkbook.Sheets("Sheet2").Tab.ColorIndex = xlNone Then
ActiveWorkbook.Sheets("Sheet2").Tab.ColorIndex = 6
Else
ActiveWorkbook.Sheets("Sheet2").Tab.ColorIndex = xlNone
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,211,792
Messages
6,103,995
Members
447,889
Latest member
birdman15

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