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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Zack Barresse

MrExcel MVP
Joined
Dec 9, 2003
Messages
10,881
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
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.
 

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
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
 

Forum statistics

Threads
1,171,433
Messages
5,875,505
Members
433,131
Latest member
ThatOneDude

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
Top