Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default want to change tab color based on the info in a cell.

I am trying to automate somre tracking on a multiple tab worksheet. so that
when a value in cell X is = X it changes the tab to green to show its done.

Sub Tab_color_change()
'
' Tab_color_change Macro
' Macro recorded 8/12/2008 by BRC
'

'
Sheets("Test log ").Select
If t39 = 10 Then
ActiveWorkbook.Sheets("Test log ").Tab.ColorIndex = 4
Else
ActiveWorkbook.Sheets("Test log ").Tab.ColorIndex = 3
End If
End Sub

it runs no errors but it doesn't matter whats in cell T39 it turns the tab
red.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default want to change tab color based on the info in a cell.

try this

Sub test()
With Sheets("Test log")
If .Range("t39") = 10 Then
.Tab.ColorIndex = 4
Else
.Tab.ColorIndex = 3
End If
End With
End Sub



--


Gary


"BRC" wrote in message
...
I am trying to automate somre tracking on a multiple tab worksheet. so that
when a value in cell X is = X it changes the tab to green to show its done.

Sub Tab_color_change()
'
' Tab_color_change Macro
' Macro recorded 8/12/2008 by BRC
'

'
Sheets("Test log ").Select
If t39 = 10 Then
ActiveWorkbook.Sheets("Test log ").Tab.ColorIndex = 4
Else
ActiveWorkbook.Sheets("Test log ").Tab.ColorIndex = 3
End If
End Sub

it runs no errors but it doesn't matter whats in cell T39 it turns the tab
red.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default want to change tab color based on the info in a cell.

I didn't even know you could change the tab color! But I'm pretty sure I see
what the problem is: Unless there's more to the code than this, you meant
t39 to indicate a cell, but VBA doesn't know that; it's clear to VBA that t39
is an undeclared variable name, which is initialized to Empty, which
evaluates as 0. Zero is never = 10, so this program always takes the second
fork. What you need is to change the If statement so VBA knows you're
referring to a cell with that address, something like this:

If ActiveWorkbooks.Sheets("Test log ").Range("T39") = 10 Then
ActiveWorkbook.Sheets("Test log ").Tab.ColorIndex = 4
Else
ActiveWorkbook.Sheets("Test log ").Tab.ColorIndex = 3
End If

....or, to make it a little simpler:

With ActiveWorkbooks.Sheets("Test log ")
If .Range("T39") = 10 Then
.Tab.Colorindex = 4
Else
.Tab.ColorIndex = 3
End If
End With

--- "BRC" wrote:
I am trying to automate somre tracking on a multiple tab worksheet. so that
when a value in cell X is = X it changes the tab to green to show its done.

Sub Tab_color_change()
Sheets("Test log ").Select
If t39 = 10 Then
ActiveWorkbook.Sheets("Test log ").Tab.ColorIndex = 4
Else
ActiveWorkbook.Sheets("Test log ").Tab.ColorIndex = 3
End If
End Sub

it runs no errors but it doesn't matter whats in cell T39 it turns the tab
red.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default want to change tab color based on the info in a cell.

Thanks that did the trick :) only 10 tabs to write the code for I looked ar
..range but didn't quite get it thought it wanted a range of cells. Thank you
very much

"Gary Keramidas" wrote:

try this

Sub test()
With Sheets("Test log")
If .Range("t39") = 10 Then
.Tab.ColorIndex = 4
Else
.Tab.ColorIndex = 3
End If
End With
End Sub



--


Gary


"BRC" wrote in message
...
I am trying to automate somre tracking on a multiple tab worksheet. so that
when a value in cell X is = X it changes the tab to green to show its done.

Sub Tab_color_change()
'
' Tab_color_change Macro
' Macro recorded 8/12/2008 by BRC
'

'
Sheets("Test log ").Select
If t39 = 10 Then
ActiveWorkbook.Sheets("Test log ").Tab.ColorIndex = 4
Else
ActiveWorkbook.Sheets("Test log ").Tab.ColorIndex = 3
End If
End Sub

it runs no errors but it doesn't matter whats in cell T39 it turns the tab
red.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default want to change tab color based on the info in a cell.

Bob thank you. I'm sure between you and Gary Ill be able to work things out
and make things a little smoother. :) will probably even create a button to
run the macro when I update the fields. Again thanks for the help.

"Bob Bridges" wrote:

I didn't even know you could change the tab color! But I'm pretty sure I see
what the problem is: Unless there's more to the code than this, you meant
t39 to indicate a cell, but VBA doesn't know that; it's clear to VBA that t39
is an undeclared variable name, which is initialized to Empty, which
evaluates as 0. Zero is never = 10, so this program always takes the second
fork. What you need is to change the If statement so VBA knows you're
referring to a cell with that address, something like this:

If ActiveWorkbooks.Sheets("Test log ").Range("T39") = 10 Then
ActiveWorkbook.Sheets("Test log ").Tab.ColorIndex = 4
Else
ActiveWorkbook.Sheets("Test log ").Tab.ColorIndex = 3
End If

...or, to make it a little simpler:

With ActiveWorkbooks.Sheets("Test log ")
If .Range("T39") = 10 Then
.Tab.Colorindex = 4
Else
.Tab.ColorIndex = 3
End If
End With

--- "BRC" wrote:
I am trying to automate somre tracking on a multiple tab worksheet. so that
when a value in cell X is = X it changes the tab to green to show its done.

Sub Tab_color_change()
Sheets("Test log ").Select
If t39 = 10 Then
ActiveWorkbook.Sheets("Test log ").Tab.ColorIndex = 4
Else
ActiveWorkbook.Sheets("Test log ").Tab.ColorIndex = 3
End If
End Sub

it runs no errors but it doesn't matter whats in cell T39 it turns the tab
red.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default want to change tab color based on the info in a cell.

You may want to look at Worksheet_Change events to have it change the tab
color in real time instead of having to run another macro.
--
HTH,
Barb Reinhardt



"BRC" wrote:

I am trying to automate somre tracking on a multiple tab worksheet. so that
when a value in cell X is = X it changes the tab to green to show its done.

Sub Tab_color_change()
'
' Tab_color_change Macro
' Macro recorded 8/12/2008 by BRC
'

'
Sheets("Test log ").Select
If t39 = 10 Then
ActiveWorkbook.Sheets("Test log ").Tab.ColorIndex = 4
Else
ActiveWorkbook.Sheets("Test log ").Tab.ColorIndex = 3
End If
End Sub

it runs no errors but it doesn't matter whats in cell T39 it turns the tab
red.

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
Change tab color based on current color of a cell MarkT Excel Discussion (Misc queries) 0 May 22nd 08 05:46 PM
Excel: Syntax to change cell color based on color of another cell davew18 Excel Worksheet Functions 1 January 4th 07 01:24 PM
change fill color of a range of cells based on color of a cell? DarMelNel Excel Programming 0 March 2nd 06 06:35 PM
Set color of cell based on info on another sheet? 43fan Excel Worksheet Functions 2 December 13th 05 07:53 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 08:40 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"