0

我需要一个 VBA 代码来循环仅遍历 range1(AA:AB) 中的那些行,这些行在单元格 AA 中的值在 Col A 中找不到。

例如

A
1
2
4

AA AB
1  Jon
3  Bob
4  Frank
5  Hank

在这个例子中,我只需要遍历包含 Bob 和 Hank 的行(2 次迭代)

4

1 回答 1

0
Sub cycle()

On Error GoTo Unmatched

Set used_range = ActiveSheet.UsedRange
For Each Line In used_range.Rows
    Key = Cells(Line.Row, 2).Value
    If (Key <> "") Then
        x = Application.WorksheetFunction.VLookup(Key, used_range, 1, False)
        End If
    Next Line
Exit Sub

Unmatched:
MsgBox (Cells(Line.Row, 2).Value & " " & Cells(Line.Row, 3).Value)
Resume Next

End Sub

一些注意事项 - 我在测试中使用了 B 列和 C 列(索引 2 和 3) - 将适当的列索引号替换为您的电子表格

把你需要做的瘦gs放在代码之后Unmatched

于 2013-05-03T21:06:57.790 回答