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

for every value in given cell, locate and highlight the same value in data

我目前使用的公式如下:

Columns("D:D").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=$D1='General Profiling'!$B"
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 之间输入了一个值,然后在不同的电子表格中突出显示这些值?

尽量避免使用 Range .Select and Range .Activate 方法¹。

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

如果你能改一下就更好了ActiveSheet property to the name or codename of the Worksheet Object


请参阅 How to avoid using Select in Excel VBA macros 了解更多摆脱依赖 select 并激活以实现目标的方法。