以下代码适用于我的工作簿中的大多数工作表:
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
行上失败,错误消息类型不匹配的工作表上有rUsedRange.FormatConditions.Count = 34
,其中许多都是图标集。
为什么代码在此表上失败?我该如何解决?
答案 0 :(得分:6)
FormatConditions
集合包括FormatCondition
,DataBar
,AboveAverage
,ColorScale
,UniqueValues
,Top10
和{{1对象,而不仅仅是IconSetCondition
个对象,因此您需要将FormatCondition
变量声明为fc
。