第2个回答 2021-04-03
把代码写在ThisWorkbook 或模块里,默认是第1列第1行数据开始到最后一行,根据需要更改你实际的起始行列即可。
Sub 对比数据2()
ThisWorkbook.Activate
Dim shtA As Object, shtB As Object
Dim rngCLA As Range, rngCLB As Range
Set shtA = Sheets("Sheet1")
Set shtB = Sheets("Sheet2")
For Each rngCLA In Range(shtA.Cells(1, 1), shtA.Cells(shtA.Cells(Rows.Count, 1).End(xlUp).Row, 1))
For Each rngCLB In Range(shtB.Cells(1, 1), shtB.Cells(shtB.Cells(Rows.Count, 1).End(xlUp).Row, 1))
If rngCLA.Value = rngCLB.Value Then
'shta.cells(..........
'
Exit For
End If
Next
Next
Set rngCLA = Nothing
Set rngCLB = Nothing
Set shtA = Nothing
Set shtB = Nothing
End Sub