简体   繁体   English

VBA-如何根据公式/单元格值更改标签颜色(跨多个标签)

[英]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). 我有一个工作簿,其中有多个选项卡-50个原始数据表和50个“分析”表位于每个数据表旁边(因此,数据表1,分析表1,数据表2,分析表2等等)。

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). 因此,如果每个分析表中的单元格D25都是该公式的位置(类似于= if(and(X = True,Y = True,Z = True),“ True”,“ False”),我该怎么写该模块仅适用于工作表名称中带有“分析”的工作表名称,并且如果我添加新的标签,则不必重写(例如,我得到了60个标签而不是50个标签集)。

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 假设“ False”表示红色

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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