Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 39
Default Change Tab colour using Macro

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.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default Change Tab colour using Macro

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)

"Rajat" wrote in message
...
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.



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 39
Default Change Tab colour using Macro

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.
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default Change Tab colour using 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)

"Rajat" wrote in message
...
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.



  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 39
Default Change Tab colour using Macro

Thanx a lot for the help Bob
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Macro - change printer Samrcat Excel Discussion (Misc queries) 14 June 28th 06 05:47 PM
how you change font colour in header/footer? Jo Lant Excel Discussion (Misc queries) 1 June 26th 06 12:40 PM
change a cell background colour to my own RGB colour requirements Stephen Doughty Excel Discussion (Misc queries) 4 June 16th 06 01:08 PM
Excel - conditional formating on graphs. Change colour on a value Peter Shore Charts and Charting in Excel 5 June 9th 06 06:10 AM
Event Macro adjustment needed - need to change font color also nick s Excel Worksheet Functions 2 November 28th 05 05:50 PM


All times are GMT +1. The time now is 03:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"