Sub compare2sheetsex() 'and highlight the diffrence
Dim wb1 As Workbook, wb2 As Workbook, sh1 As Worksheet, sh2 As Worksheet
Set wb1 = Workbooks(InputBox("enter b1"))
Set wb2 = Workbooks(InputBox("enter b2"))
Set sh1 = wb1.Sheets(InputBox("enter s1"))
Set sh2 = wb2.Sheets(InputBox("enter s2"))
rcount = sh1.UsedRange.Rows.Count
ccount = sh1.UsedRange.Columns.Count
Dim r As Long, c As Integer
For r = 1 To rcount
For c = 1 To ccount
If sh1.Cells(r, c) <> sh2.Cells(r, c) Then
sh2.Cells(r, c).Interior.ColorIndex = 6
End If
Next c
Next r
Set sh1 = Nothing
Set sh2 = Nothing
End Sub
問:我試圖比較兩張不同的工作簿,但我無法執行上面的代碼。如何比較不同工作簿中的兩張紙並突出顯示第二張紙上的差異?
一些未聲明的變量
當您嘗試執行上述代碼時會發生什麼?你有錯誤嗎?或者只是意外的結果? –
我無法執行,是的,我收到一條錯誤消息。 – Sevak