Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Worksheet Functions / October 2006

Tip: Looking for answers? Try searching our database.

Change Tab colour using Macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rajat - 24 Oct 2006 08:10 GMT
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
----------------------------------
my problem is that if rename the worksheet from "Sheet1" to say "1" the
macro has an Run Time Error 9.
I changed the VBA code to "Sheet1" to "1" but nothing happened, help
requested.
Bob Phillips - 24 Oct 2006 09:23 GMT
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

Signature

HTH

Bob Phillips

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

> i used the following VBA code to chage the colour of using a condition -
> Sub test()
[quoted text clipped - 9 lines]
> I changed the VBA code to "Sheet1" to "1" but nothing happened, help
> requested.
Rajat - 24 Oct 2006 09:49 GMT
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.
Bob Phillips - 24 Oct 2006 11:43 GMT
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

Signature

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.
Rajat - 24 Oct 2006 14:31 GMT
Thanx a lot for the help Bob
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.