简体   繁体   中英

VBA - how to change tab color (across multiple tabs) based on formula/cell value

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!!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM