【问题标题】:VBA to compare values in two columns, and copy the row of missing values to a new worksheetVBA比较两列中的值,并将缺失值行复制到新工作表
【发布时间】:2014-05-29 07:27:09
【问题描述】:

我是新手,所以真的不知道从哪里开始。

这是我想要实现的宏的最佳描述:

将工作表“E Dump”的“B”列中的所有值与工作表“F Dump”的“G”列中的值进行比较。

出现在“B”列而非“E”列中的任何值将整个行从工作表“E Dump”复制到工作表“不匹配”的下一个可用行中。

非常感谢任何帮助!

【问题讨论】:

    标签: vba excel compare


    【解决方案1】:

    下面是我刚刚编写的一些工作代码。这也可以使用搜索功能来完成,但无论如何这应该有效。我唯一的其他评论是,如果您发布自己的尝试,您将更有可能得到回复!

    Sub compareAndCopy()
    
    Dim lastRowE As Integer
    Dim lastRowF As Integer
    Dim lastRowM As Integer
    Dim foundTrue As Boolean
    
    ' stop screen from updating to speed things up
    Application.ScreenUpdating = False
    
    lastRowE = Sheets("E Dump").Cells(Sheets("E Dump").Rows.Count, "B").End(xlUp).row
    lastRowF = Sheets("F Dump").Cells(Sheets("F Dump").Rows.Count, "G").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("E Dump").Cells(i, 2).value = Sheets("F Dump").Cells(j, 7).value Then
            foundTrue = True
            Exit For
        End If
    
    Next j
    
    If Not foundTrue Then
        'MsgBox ("didnt find string: " & Sheets("E Dump").Cells(i, 2).value)
        Sheets("E Dump").Rows(i).Copy Destination:= _
        Sheets("Mismatch").Rows(lastRowM + 1)
        lastRowM = lastRowM + 1
    
    End If
    
    
    Next i
    
    ' stop screen from updating to speed things up
    Application.ScreenUpdating = True
    
    End Sub
    

    【讨论】:

    • 谢谢你,正是我想要的!我已经使用搜索功能做了一个解决方法,但这更干净。将来我会确保在发布之前尝试编写一些代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-08
    • 1970-01-01
    • 2021-10-04
    • 2017-08-28
    • 1970-01-01
    • 2021-08-31
    相关资源
    最近更新 更多