Change Tab colour using Macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i used the following VBA code to chage the colour of using a condition -
Sub test()
If Sheets("Sheet1").Range("A1").Value <> "hello" Then
Sheets("Sheet1").Tab.ColorIndex = 6
Else
Sheets("Sheet1").Tab.ColorIndex = -4142
End If
End Sub
 
Worksheets also have a codename that you can use. It starts the same as the
sheet name, but if the sheet name is changed. the codename isn't

Sub test()
If Sheet1.Range("A1").Value <> "hello" Then
Sheet1.Tab.ColorIndex = 6
Else
Sheet1.Tab.ColorIndex = -4142
End If
End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
thanx for your help.

But i've another problem, can i extend the Macro to all the sheets of the
workbook.

Say workbook have 30 sheets. can it be done using the same macro.
 
Sub test()
Dim sh As Worksheet

For Each sh In Activeworkbook.Worksheets
If sh.Range("A1").Value <> "hello" Then
sh.Tab.ColorIndex = 6
Else
sh.Tab.ColorIndex = -4142
End If
Next sh
End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top