0

I have a workbook that has multiple tabs - 50 raw data sheets and 50 "analysis" sheets that sit next to each data sheet (so data sheet 1, analysis sheet 1, data sheet 2, analysis sheet 2 and so on).

I want to be able to have the tab color for each analysis sheet turn red if a master "bust" formula is triggered in each analysis tab. So if cell D25 in each analysis sheet was the location of that formula (which is something like =if(and(X=True, Y=True, Z=True),"True","False"), how can I write the module to only apply to the sheet names with 'Analysis' in the sheet name, and not have to be re-written if I add new tabs (say I got to 60 instead of 50 sets of tabs).

Many thanks in advance!!

1
  • You could start by recording a macro of you manually changing the Tab color and read THIS about Worksheet_Change Event. Then if you have problems, edit your question with your code so we can help debug.
    – simpLE MAn
    Feb 12, 2014 at 16:49

1 Answer 1

0

Place the following Event macro in the code area of each analysis worksheet:

Private Sub Worksheet_Calculate()
    If Range("D25").Text = "False" Then
        ActiveWorkbook.ActiveSheet.Tab.Color = 255
    Else
        ActiveWorkbook.ActiveSheet.Tab.Color = 15773696
    End If
End Sub

this assumes that "False" means red

5
  • 3
    Or use a single Workbook_SheetCalculate in the ThisWorkbook module - it get a parameter indicating which sheet was calculated. Feb 12, 2014 at 17:16
  • Thanks - that was along the lines of what I already had, but can't figure out how to apply that to all sheets with the word 'Analysis' in the tab name. I don't want to have to copy that code into each worksheet, and my number of worksheets will be expanding so don't want to have to remember to go back and copy the code over again...
    – Dan85
    Feb 12, 2014 at 17:28
  • A tiny trick! Once you have placed the code in some analysis sheet, you can use that sheet as a sort of template...........when you need a new analysis sheet, copy the old one rather than create a new one from scratch..........the copy should already have the macro "in place" Feb 12, 2014 at 17:36
  • Okay so just tried this on my workbook, it didn't seem to work as expected? I put the code into Sheet 1, D25 was set to reference "FALSE" as text, and the sheet turned a Cyan color. Then I deleted the cell contents, and the sheet color stayed Cyan.
    – Dan85
    Feb 12, 2014 at 22:19
  • The code relies on a calculation being performed......the cell must contain a formula and the formula must change result! Feb 12, 2014 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.