VBA - 如何根据公式/单元格值更改标签颜色(跨多个选项卡) [英] VBA - how to change tab color (across multiple tabs) based on formula/cell value

查看:182
本文介绍了VBA - 如何根据公式/单元格值更改标签颜色(跨多个选项卡)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作簿有多个选项卡 - 50个原始数据表和50个分析表,位于每个数据表旁边(所以数据表1,分析表1,数据表2,分析表2等)

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).

如果在每个分析标签中触发了主突破公式,我希望能够将每个分析表的选项卡颜色变为红色。因此,如果每个分析表中的单元格D25是该公式的位置(它是类似于if(和(X = True,Y = True,Z = True),True,False),我如何写该模块仅在工作表名称中使用Analysis应用于工作表名称,如果我添加了新的选项卡,则不必重新写入(说明我已经获得了60个选项卡)。

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).

非常感谢提前!!

推荐答案

将以下事件宏放在代码区域每个分析工作表:

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

这假定False表示红色

这篇关于VBA - 如何根据公式/单元格值更改标签颜色(跨多个选项卡)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆