gpt4 book ai didi

excel - 在 If 语句中使用 Font.Color 作为条件

转载 作者:行者123 更新时间:2023-12-04 21:14:18 25 4
gpt4 key购买 nike

我目前正在尝试使用字体颜色作为在 if 语句中进行检查的条件。这似乎非常容易,但 VBA 似乎无法做到。

我无法显示我的实际代码,因为其中包含专有信息,但我什至尝试了我的代码的简单版本但无济于事。该代码如下所示。

Sub Testing()

Cells(1,1).Font.Color = -16776961
If Cells(1,1).Font.Color = -16776961 Then
Cells(1,3) = "Worked!"
Else
Cells(1,3) = "Didn't Work!"
End If

End Sub

第一行代码实际上将字体颜色或单元格 A1 更改为红色。但是,由于某种原因,条件语句不起作用。

最佳答案

使用 RGB代替功能。 (不确定负值来自哪里?)

Sub Testing()

Cells(1, 1).Font.Color = RGB(255, 0, 0)
If Cells(1, 1).Font.Color = RGB(255, 0, 0) Then
Cells(1, 3) = "Worked!"
Else
Cells(1, 3) = "Didn't Work!"
End If

End Sub

关于excel - 在 If 语句中使用 Font.Color 作为条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55868788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com