使用Range.find方法查找具有特定颜色索引的单元格

我想find与范围相同的colorindex单元格所以我logging了一个macros来find一个颜色的细胞,并应用到它的代码这样的。 但它不起作用。

如何find具有特定颜色索引的单元格?

For Each r In rngC lcolorID = r.Offset(, 1).Interior.ColorIndex With wsD.UsedRange With Application.FindFormat.Interior .PatternColorIndex = xlAutomatic .Color = lcolorID End With Set c = .Find(What:="", After:=ActiveCell, _ LookIn:=xlFormulas, LookAt:= xlPart, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False, MatchByte:=False, _ SearchFormat:=True) If Not c Is Nothing Then Debug.Print c.Address End If End With Next r 

 If Cell.Interior.ColorIndex = yourColorIndex Then 'using your color variable 'your actions here End If 

将上面的if条件放在for循环中,在所有行中都可以使用,它应该可以工作! 并用您正在使用的循环遍历工作表中的循环replace您当前在项目中处理的特定单元格的“单元格”。 如果您的工作表名称是"Sheet"则使用:

 Sheets("Sheet").Cell(rowindex, columnindex).Interior.ColorIndex 

其中rowindexrowindex是你正在循环的索引。

With Application.FindFormat.Interior尝试With Application.FindFormat.Interior

您可能已经设置了一些格式,可能会阻止您匹配所需的单元格。