对于范围内的每个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集合包括FormatConditionDataBarAboveAverageColorScaleUniqueValuesTop10IconSetCondition对象,而不仅仅是FormatCondition对象,所以您需要将您的fcvariables声明为Object