在工作表中搜索一系列连续的行单元格
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中每行table2中的前三个单元格?鉴于表格具有相同的格式。
范围和细胞似乎不起作用,因为我不能使用计数器
答案 0 :(得分: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