0

我在 Excel 中为 3 张工作表编写代码,工作表 1 将显示来自 Sheet3 的 Sheet2 中未出现的数据,为了完成此操作,代码如下;

Dim r As Excel.Range
Dim cell As Excel.Range
Set r = Sheet3.Range(Sheet3.Cells(1, 1), Sheet3.Cells(Rows.Count, 1).End(xlUp))
Dim curRowSheet1 As Long

curRowSheet1 = 1

For Each cell In r
    Set rFind = Sheet2.Range("A:A").Find(cell.Value)



    If (rFind Is Nothing) Then
        cell.EntireRow.Copy Sheet1.Cells(curRowSheet1, 1)
        curRowSheet1 = curRowSheet1 + 1
    End If
Next cell

注意:我试图在第 9 行“SET rFind”下包含第二个 .FIND,如果在列 (“A:Ä”) 中查找单元格值,然后它还会验证列中的值是否相同 (“B: B") 来自第 2 和第 3 页,我想我可以使用 Offset() 函数来比较这些数据,对此的任何建议将不胜感激!!!!

谢谢。

4

1 回答 1

0

Instead of Range.Find, I would recommend using WorksheetFunction.CountIfs

Sub tgr()

    Dim ACell As Range

    For Each ACell In Sheet3.Range("A1", Sheet3.Cells(Rows.Count, "A").End(xlUp)).Cells
        If WorksheetFunction.CountIfs(Sheet2.Columns("A"), ACell.Value, Sheet2.Columns("B"), ACell.Offset(, 1).Value) = 0 Then
            ACell.EntireRow.Copy Sheet1.Cells(Rows.Count, "A").End(xlUp).Offset(1)
        End If
    Next ACell

End Sub
于 2013-09-04T16:08:34.367 回答