1

So, I'm new to VBA, so go easy.

I have two different worksheets-- Merged Nativity Codes and 2007-2011 Nativity Codes. I want to iterate through all the values in the 2007-2011 codes (Column B) and compare that to the values in Column A of Merged Nativity Codes. I want to highlight the content that is in the 2007-2011 codes, but not in the Merged Nativity Codes.

I tried my hand at this VBA macro:

Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim ws3 As Worksheet

Set ws1 = Worksheets("2002-2006 Nativity Codes")
Set ws2 = Worksheets("Merged Nativity Codes")
Set ws3 = Worksheets("2007-2011 Nativity Codes")


For Each i In ws3.Range("B2:B154")
    For Each C In ws2.Range("A1:A138")
        If i.Cells.Value <> C.Cells.Value Then
            i.Cells.Interior.ColorIndex = 3
        End If
    Next C
Next i

But the problem is that " If i.Cells.Value <> C.Cells.Value Then" will be triggered if only one doesn't match. I'm looking for something like the "all()" function in Python. Does this exist? Easier way to do this?

4

1 回答 1

2

通过采取简单的方法回答了我自己的问题。我首先用红色突出显示了感兴趣的列。然后,如果找到匹配项,我将宏更改为 CLEAR 列中的颜色(如果找不到匹配项,则将其着色为红色)。

**注意-我是这个东西的新手,所以如果你们有更有效的方法来回答这个问题,我很乐意学习。我觉得 vLookUp 可能有用。

For Each i In ws1.Range("B2:B154")
    For Each C In ws2.Range("A1:A138")
        If i.Cells.Value = C.Cells.Value Then
            i.Cells.Interior.ColorIndex = xlNone
        End If
    Next C
Next i
于 2013-04-30T17:19:19.310 回答