【发布时间】:2021-03-18 08:51:36
【问题描述】:
我的 Excel 中有一个数据验证下拉菜单。如果有人将无效数据复制粘贴到这些下拉列表中,如果粘贴的值与下拉数据不匹配,我将使用条件格式以红色突出显示文本。 现在我正在尝试获取此下拉列表的文本颜色,以防使用 VBA 的数据不匹配。但我得到 -4105 作为颜色索引。
Function GetColorText(pRange As Range) As String
Dim xOut As Variant
Dim xValue As String
Dim i As Long
xValue = pRange.Text
MsgBox "cell value = " & xValue
xOut = pRange.DisplayFormat.fornt.Color
MsgBox "Color = " & xOut
GetColorText = xOut
End Function
如果数据不匹配,有人可以帮助获取文本颜色
【问题讨论】:
-
要检查条件格式设置的颜色,请使用
pRange-DisplayFormat.Interior.Color。见stackoverflow.com/q/47419269/7599798 -
感谢您的快速响应。但这对我也不起作用。我在模块中编写的函数并在工作表中将此函数称为 excel 公式。
-
不明白这与函数有何关系。顺便说一句:如果要检查文本颜色,请使用
pRange.DisplayFormat.Font.Color -
请不要在 cmets 中发帖。编辑您的问题并将其放在那里。