Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 比较两个不同表中的行_Vba_Excel - Fatal编程技术网

Vba 比较两个不同表中的行

Vba 比较两个不同表中的行,vba,excel,Vba,Excel,我有两张工作表要比较。有时可能会添加、删除或更改整行数据。我需要将此工作表与其他工作表进行比较 例如,如果一个工作表看起来像: (Sheet 1) Max J 89231 Sam L 82313 Penny H 23456 Mary K 91423 (Sheet 2) Sam L 82313 (Max J Removed) John S 71234 (Penny H changed to John S) Mary K 91423 Thomas N 18123 (Thomas N a

我有两张工作表要比较。有时可能会添加、删除或更改整行数据。我需要将此工作表与其他工作表进行比较

例如,如果一个工作表看起来像:

(Sheet 1)
Max J 89231 
Sam L 82313
Penny H 23456
Mary K 91423
(Sheet 2)
Sam L 82313    (Max J Removed)
John S 71234   (Penny H changed to John S)
Mary K 91423
Thomas N 18123 (Thomas N added)
下一页看起来像:

(Sheet 1)
Max J 89231 
Sam L 82313
Penny H 23456
Mary K 91423
(Sheet 2)
Sam L 82313    (Max J Removed)
John S 71234   (Penny H changed to John S)
Mary K 91423
Thomas N 18123 (Thomas N added)
如何使用宏显示两张图纸的行差异,例如在sheet3中

(Sheet 3)
Max J 89231 
John S 71234  
Thomas N 18123

每张纸上都有两个环,分别检查表1和表2,将差异插入表3,然后将表2和表1,并将差异插入表3

在半伪半vba代码中,类似于Sheet1:

for i = beginning row in Sheet 1 to last Row in Sheet1
   'matchFound variable concludes if match is found. Initially no match
   matchFound=false
   continue=true ' boolean to tell us whether its worth proceeding if we have identified a match
   if (continue) then
       for j = beginning row in Sheet 2 to last Row in Sheet2
            'if Sheet1 row has been matched in a row in Sheet2 
            if Sheet1.Cells(i,1).Value = Sheet2.Cells(j,1).Value and
                 Sheet1.Cells(i,2).Value = Sheet2.Cells(j,2).Value then
                  matchFound = true
                  continue=false
            endif
        next j
    endif

    'no match found
    if matchFound = false then
           sheet3.Range(last used row + 1, 1).Value = Sheet1.Cells(i,1).Value
           sheet3.Range(last used row + 1, 2).Value = Sheet1.Cells(i,2).Value

    endif

next i

对sheet2也使用上述逻辑,但会检查sheet2中的逻辑,而不是Sheet1中的逻辑,并将其添加到Sheet3中-因此,这次sheet2是外部for循环

图纸的布局是什么?特别是——在第一列中查看给定行是否已被添加或删除就足够了吗?另外--两个工作表共用的行的相对顺序在两个工作表中是否相同,或者除了添加或删除行之外,还可以对行进行排列?