如何比较序列号的主列表并将其与单独的列表进行比较并将其标记为重复?

时间:2016-10-12 16:17:26

标签: excel vba excel-vba

Sheets("Die Sizes").Select

Columns("A:A").Select
Selection.FormatConditions.Add Type:=xlTextString, String:= _
    "=cells(i,ForgeSchedule!B2)", TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent6
    .TintAndShade = 0.399945066682943
End With
Selection.FormatConditions(1).StopIfTrue = False

这是我到目前为止所拥有的。这会将辅助列表中的特定单元格与主列表进行比较。这意味着我必须一次重新运行这个,改变" B2"到B3一直到B3200。我怎样才能让它自动完成?我对VBA很新。

1 个答案:

答案 0 :(得分:0)

听起来你只需要一个循环。也许是这样的(航空代码):

Dim lngRow As Long

Sheets("Die Sizes").Select

Columns("A:A").Select
For lngRow = 2 To 3200
    Selection.FormatConditions.Add Type:=xlTextString, String:= _
        "=cells(i,ForgeSchedule!B" & lngRow & ")", TextOperator:=xlContains
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent6
        .TintAndShade = 0.399945066682943
    End With
    Selection.FormatConditions(1).StopIfTrue = False
Next lngRow