#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default tab color

I would like to alter the color of the tab based upon a value in an array of
cells. In my example if the range is A1:A50 and just one cell has a number in
it then this will cause the tab to change color. Here is some code that I
found but cannot get it to work. Any suggestions?
i.e.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Address = "$A$1..$A$50" Then
If Target.Value0 Then Sh.Tab.ColorIndex = 3
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default tab color

Right-click the Tab, View Code, Paste this code

Private Sub Worksheet_Change(ByVal Target As Range)
If Application.WorksheetFunction.CountA(Range("A1:A50 ")) = 1 Then
Target.Parent.Tab.ColorIndex = 3
Else
Target.Parent.Tab.ColorIndex = 5
End If
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"briank" wrote in message
...
I would like to alter the color of the tab based upon a value in an array
of
cells. In my example if the range is A1:A50 and just one cell has a number
in
it then this will cause the tab to change color. Here is some code that I
found but cannot get it to work. Any suggestions?
i.e.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
If Target.Address = "$A$1..$A$50" Then
If Target.Value0 Then Sh.Tab.ColorIndex = 3
End If
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default tab color

Thank you. It works gr8!

"Rob van Gelder" wrote:

Right-click the Tab, View Code, Paste this code

Private Sub Worksheet_Change(ByVal Target As Range)
If Application.WorksheetFunction.CountA(Range("A1:A50 ")) = 1 Then
Target.Parent.Tab.ColorIndex = 3
Else
Target.Parent.Tab.ColorIndex = 5
End If
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"briank" wrote in message
...
I would like to alter the color of the tab based upon a value in an array
of
cells. In my example if the range is A1:A50 and just one cell has a number
in
it then this will cause the tab to change color. Here is some code that I
found but cannot get it to work. Any suggestions?
i.e.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
If Target.Address = "$A$1..$A$50" Then
If Target.Value0 Then Sh.Tab.ColorIndex = 3
End If
End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default tab color

Follow Up: If I change the spreadsheet to elimate data in the cell range
A1..A50, the tab still stays the same color. Is there a "refresh" command
that I can add?

"Rob van Gelder" wrote:

Right-click the Tab, View Code, Paste this code

Private Sub Worksheet_Change(ByVal Target As Range)
If Application.WorksheetFunction.CountA(Range("A1:A50 ")) = 1 Then
Target.Parent.Tab.ColorIndex = 3
Else
Target.Parent.Tab.ColorIndex = 5
End If
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"briank" wrote in message
...
I would like to alter the color of the tab based upon a value in an array
of
cells. In my example if the range is A1:A50 and just one cell has a number
in
it then this will cause the tab to change color. Here is some code that I
found but cannot get it to work. Any suggestions?
i.e.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
If Target.Address = "$A$1..$A$50" Then
If Target.Value0 Then Sh.Tab.ColorIndex = 3
End If
End Sub




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default tab color

The code works as so:
Whenever the worksheet changes, it counts the number of entries in A1:A50
If it counts 1 then color is 3 otherwise the color is 5

To see whether the code is running or not try this code:

Private Sub Worksheet_Change(ByVal Target As Range)
If Application.WorksheetFunction.CountA(Range("A1:A50 ")) = 1 Then
MsgBox "Triggered 1"
' Target.Parent.Tab.ColorIndex = 3
Else
MsgBox "Triggered not 1"
' Target.Parent.Tab.ColorIndex = 5
End If
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"briank" wrote in message
...
Follow Up: If I change the spreadsheet to elimate data in the cell range
A1..A50, the tab still stays the same color. Is there a "refresh" command
that I can add?

"Rob van Gelder" wrote:

Right-click the Tab, View Code, Paste this code

Private Sub Worksheet_Change(ByVal Target As Range)
If Application.WorksheetFunction.CountA(Range("A1:A50 ")) = 1 Then
Target.Parent.Tab.ColorIndex = 3
Else
Target.Parent.Tab.ColorIndex = 5
End If
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"briank" wrote in message
...
I would like to alter the color of the tab based upon a value in an
array
of
cells. In my example if the range is A1:A50 and just one cell has a
number
in
it then this will cause the tab to change color. Here is some code
that I
found but cannot get it to work. Any suggestions?
i.e.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
If Target.Address = "$A$1..$A$50" Then
If Target.Value0 Then Sh.Tab.ColorIndex = 3
End If
End Sub






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
Powerpoint / Excel: custom pp RGB color doesn't match identical Excelcustom RGB color mikewillnot Charts and Charting in Excel 1 February 26th 08 05:22 PM
Can't format cell color/text color in Office Excel 2003 in fil Tony S Excel Discussion (Misc queries) 1 December 21st 07 01:41 PM
Can't format cell color/text color in Office Excel 2003 in files . albertaman Excel Discussion (Misc queries) 0 February 16th 06 03:56 AM
My excel 2003 wont let me fill cells with color or color the tabs. trizog New Users to Excel 2 February 22nd 05 06:43 PM
Browse Forms Controls and change TextBox color based on cell color StefanW Excel Programming 2 November 21st 04 07:06 PM


All times are GMT +1. The time now is 03:24 PM.

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"