0

在工作表中搜索一系列连续的行单元格

    h1 h2 h3 h4 h5             h1 h2 h3 h4 h5
    1  2  3  6  7              1  2  3  8  9
    2  2  2  4  5              3  3  3  2  1
    table 1                    table 2

我如何编写一个循环来搜索表 1 中每行表 2 中的前三个单元格?鉴于表格具有相同的格式。

范围和单元格似乎不起作用,因为我不能对它们使用计数器

4

1 回答 1

0
Dim tlb1 as range,tbl2 as range
dim rw1 as range, rw2 as range

set tbl1=Range("your table1 range here")
set tbl2=Range("your table2 range here")

for each rw1 in tbl1.rows
    for each rw2 in tbl2.rows
        if rw1.cells(1)=rw2.cells(1) and rw1.cells(2)=rw2.cells(2) _
           and rw1.cells(3)=rw2.cells(3) then
           'do whatever you want to do on match...
           'Exit For 'if you want to stop when you find the first match...
        end if
    next rw2
next rw1
于 2013-07-25T20:35:15.177 回答