问题
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:
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
来源:https://stackoverflow.com/questions/21733897/vba-how-to-change-tab-color-across-multiple-tabs-based-on-formula-cell-value