将范围单元格中的文本颜色更改为白色基于两个条件:1)单元格中的值和2)另一个单元格中的文本

问题描述 投票:0回答:1

更改字体颜色的条件:

  1. 如果蒸气分数(左起第二列)= 1,则表中包含单词“液体”的列标题下的所有单元格应将字体更改为白色。

  2. 如果蒸气分数=0,则包含单词“蒸气”的列标题下的表格中的所有单元格应将字体更改为白色。

此表中有 6 个表格,我希望宏将其应用到所有 6 个表格。

Image of tables

非常感谢您的帮助。

我尝试一次处理一列,因为我现在不知道如何使用循环。

Picture of code

结果什么也没发生。对于vba我是个新手..

excel vba fonts
1个回答
0
投票

如果您尝试评估范围 D2:D17 中的所有单元格的值为 1,您可以这样做:

Dim VaporFraction As Range
Dim VaporFractionCell As Range
Dim ChangeToWhite As Boolean

ChangeToWhite = True
For Each myCell In ThisWorkbook.Worksheets("Sheet1").Range("D2:D17")
 If Not myCell.Value = 1 Then
    ChangeToWhite = False
    Exit For
 End If
Next myCell

If ChangeToWhite = True Then
    'Your code to format to white
End if

© www.soinside.com 2019 - 2024. All rights reserved.