If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Tab Color If Statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-16-09, 13:39
rbeck1231 rbeck1231 is offline
Registered User
 
Join Date: Sep 2009
Posts: 4
Question Tab Color If Statement

Does anyone know how to write the code to change the tab color of a worksheet if a True False Statement within that worksheet is False? I have Microsoft 2007. I would like the tab color to turn red if cell S21 is False and Green if cell S21 is True. If you need to know any other information let me know. Thanks!
Reply With Quote
  #2 (permalink)  
Old 09-16-09, 16:19
Ax238 Ax238 is offline
Registered User
 
Join Date: May 2009
Posts: 257
Try this:
Code:
Dim rngBool As Range, iColor As Integer
Set rngBool = ActiveSheet.Range("S21")
iColor = xlColorIndexNone
If rngBool.Value = "True" Then
    iColor = 4
ElseIf rngBool.Value = "False" Then
    iColor = 3
End If
ActiveSheet.Tab.ColorIndex = iColor
Regards,

Ax
Reply With Quote
  #3 (permalink)  
Old 09-16-09, 16:29
rbeck1231 rbeck1231 is offline
Registered User
 
Join Date: Sep 2009
Posts: 4
Do I need to do edit any of this or should it just work if i cut and paste it into the view code when I right click the tab I want it for because I did that and it didn't work. Does the tab name need to be included? If so the tab name is "Program Analysis"
Reply With Quote
  #4 (permalink)  
Old 09-16-09, 16:43
Ax238 Ax238 is offline
Registered User
 
Join Date: May 2009
Posts: 257
You'll have to put it in a sub.

Last edited by Ax238; 09-16-09 at 16:49.
Reply With Quote
  #5 (permalink)  
Old 09-16-09, 17:22
rbeck1231 rbeck1231 is offline
Registered User
 
Join Date: Sep 2009
Posts: 4
Okay. I am not familiar with subs so what exactly needs to be put into the code? Thanks Ax238
Reply With Quote
  #6 (permalink)  
Old 09-17-09, 10:20
Ax238 Ax238 is offline
Registered User
 
Join Date: May 2009
Posts: 257
I posted a link in my last response, that should give you all the information you need. It's a pretty good tutorial. I pointed you directly where you find Sub and Function declarations, but it would behoove you to read through the whole thing... especially if you want to learn how to program macros in Excel.

Ax
Reply With Quote
  #7 (permalink)  
Old 10-05-09, 11:12
Simplify Simplify is offline
Registered User
 
Join Date: Oct 2009
Posts: 6
This may sound simple, but have you tried theConditional Formating ->Highlights Cell Rules-> Text Containing..> write in TRUE and condition the cell fill as green...but then, this is simple, not sure whether I understood your goal.
Reply With Quote
  #8 (permalink)  
Old 10-05-09, 11:16
rbeck1231 rbeck1231 is offline
Registered User
 
Join Date: Sep 2009
Posts: 4
I believe that is only for changing a cell color based on the formula. The goal is to have the conditional formating of the tab itself change colors depending on an if statement within that tab which is based on several other tabs within the workbook. Hopefully this helps.
Reply With Quote
  #9 (permalink)  
Old 10-05-09, 11:19
Simplify Simplify is offline
Registered User
 
Join Date: Oct 2009
Posts: 6
Ax238 is your guy then, soory i didnt read tour definiton properly!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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