小编San*_*ets的帖子

比较2组数据并粘贴另一张纸上的任何缺失值

所以我有一张1000多行的主表和另一张"应该"具有相同数据的表.但是,实际上有时会从主服务器中丢失一些,有时在查询运行中会丢失一些.
为简单起见,我们假设唯一ID在B列中.这是我的代码,但它超级慢,只进行单向比较.

我理想的代码会运行得更顺畅一些,并从主服务器和查询中提供缺少的数据.

我问这个问题的方式有问题请告诉我.

Sub FindMissing()

    Dim lastRowE As Integer
    Dim lastRowF As Integer
    Dim lastRowM As Integer
    Dim foundTrue As Boolean


    lastRowE = Sheets("Master").Cells(Sheets("Master").Rows.Count, "B").End(xlUp).Row
    lastRowF = Sheets("Qry").Cells(Sheets("Qry").Rows.Count, "B").End(xlUp).Row
    lastRowM = Sheets("Mismatch").Cells(Sheets("Mismatch").Rows.Count, "B").End(xlUp).Row



    For i = 1 To lastRowE
        foundTrue = False
        For j = 1 To lastRowF
            If Sheets("Master").Cells(i, 2).Value = Sheets("Qry").Cells(j, 2).Value Then
                foundTrue = True
                Exit For
            End If
        Next j
        If Not foundTrue Then
            Sheets("Master").Rows(i).Copy Destination:= _
            Sheets("Mismatch").Rows(lastRowM + 1)
            lastRowM = lastRowM + 1 …
Run Code Online (Sandbox Code Playgroud)

excel vba excel-vba

1
推荐指数
1
解决办法
101
查看次数

标签 统计

excel ×1

excel-vba ×1

vba ×1