对于给定单元格中的每个值,find并突出显示数据中的相同值

我现在使用的公式如下:

Columns("D:D").Select Range(Selection, Selection.End(xlToRight)).Select Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _ "=$D1='General Profiling'!$B$6" Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority With Selection.FormatConditions(1).Interior .PatternColorIndex = xlAutomatic .Color = 65535 .TintAndShade = 0 End With Selection.FormatConditions(1).StopIfTrue = True 

然而,有时,在C6,D6等可能有价值,我也希望有条件的格式提取和突出显示。

有没有办法确定C2到C100之间是否放置了一个值,然后在不同的电子表格上突出显示这些值?

尽量避免使用范围 。select和范围 。激活方法¹。

 With ActiveSheet With .Range(.Cells(1, "D"), .Cells(1, Columns.Count).End(xlToLeft)).EntireColumn With .FormatConditions.Add(Type:=xlExpression, Formula1:= _ "=COUNTIF('General Profiling'!$B$6:$Z6, $D1)") .Interior.Color = vbYellow End With End With End With 

如果可以将ActiveSheet属性更改为工作表对象的名称或代码名,这将更好。


¹ 请参阅如何避免使用在Excel VBAmacros中select更多的方法来摆脱依靠select和激活来实现您的目标。