我有以下代码比较两张纸,并突出显示纸张1和2之间的更改。 我需要添加什么以便宏自动突出显示w2中添加的行与w1相比?因为我以前的尝试失败了,所以我有点无能为力:)
非常感谢您提前
Sub CompareSheets2()
Dim w1 As Worksheet, w2 As Worksheet
Dim lr As Long, lc As Long, c As Long
Dim d As Range, a As Range
Application.ScreenUpdating = False
Set w1 = Worksheets(ActiveWorkbook.Worksheets.Count() - 1)
Set w2 = Worksheets(ActiveWorkbook.Worksheets.Count)
With w1
lr = .Cells(Rows.Count, 1).End(xlUp).Row
lc = .Cells(1, Columns.Count).End(xlToLeft).Column
For Each d In w1.Range("A1", w1.Range("A" & Rows.Count).End(xlUp))
Set a = w2.Columns(1).Find(d.Value, LookAt:=xlWhole)
If Not a Is Nothing Then
For c = 2 To lc
If w1.Cells(d.Row, c) <> w2.Cells(a.Row, c) Then
w2.Cells(a.Row, c).Interior.ColorIndex = 6
End If
Next c
Set a = Nothing
End If
Next d
End With
w2.Activate
Application.ScreenUpdating = True
End sub