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

∥☆過路亽.° 提交于 2019-12-23 04:43:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!