对于范围内的每个fc,格式条件失败。 为什么?
以下代码适用于我的工作簿中的大多数工作表:
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
错误消息types不匹配的工作表中有rUsedRange.FormatConditions.Count = 34
其中许多是图标集。
为什么代码在这张表上失败? 我该如何解决?
FormatConditions
集合包括FormatCondition
, DataBar
, AboveAverage
, ColorScale
, UniqueValues
, Top10
和IconSetCondition
对象,而不仅仅是FormatCondition
对象,所以您需要将您的fc
variables声明为Object
。