问题描述
以下代码适用于我的工作簿中的大多数工作表:
The following code works for most sheets in my workbook:
Function IsHighlighted() As Boolean
Dim wks As Worksheet
For Each wks In ThisWorkbook.Worksheets
Dim rUsedRange As Range
Set rUsedRange = wks.UsedRange
With rUsedRange
Dim bHighlighted As Boolean
Dim fc As FormatCondition
For Each fc In .FormatConditions
If fc.Interior.Color = RGB(255, 0, 0) And fc.Font.Color = RGB(255, 255, 0) Then
bHighlighted = True
Exit For
End If
Next fc
If bHighlighted = True Then
Exit For
End If
End With
Debug.Print (wks.Name & "," & rUsedRange.FormatConditions.count)
Next wks
IsHighlighted = bHighlighted
End Function
但它在线上失败 For Each fc In .FormatConditions
with在 rUsedRange.FormatConditions.Count = 34
的工作表上,错误消息类型不匹配,其中许多是图标集。
But it fails on the line For Each fc In .FormatConditions
with the error message type mismatch on a worksheet that has rUsedRange.FormatConditions.Count = 34
out of which many are icon sets.
为什么代码在此工作表上失败?如何解决?
Why does the code fail on this sheet? How can I fix it?
推荐答案
FormatConditions
c $ c> FormatCondition , DataBar
, AboveAverage
, ColorScale
, UniqueValues
, Top10
和 IconSetCondition
对象,而不仅仅是 FormatCondition
对象,所以你需要将 fc
变量声明为对象
。
The FormatConditions
collection includes FormatCondition
, DataBar
, AboveAverage
, ColorScale
, UniqueValues
, Top10
and IconSetCondition
objects, not just FormatCondition
objects, so you need to declare your fc
variable as Object
.
这篇关于对于range.formatconditions中的每个fc失败。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!