我一直在試圖編寫一個代碼,比較兩個相同大小的表中的值,並突出顯示不匹配的值。我提出的代碼似乎只是突出了該範圍的最後一個單元。我想我在這裏可以忽略一些非常簡單的事情。任何幫助來解決這個問題將不勝感激。我正在放下下面的代碼。Excel VBA代碼來比較兩個表,並突出顯示不匹配
Sub Compare_Table()
Dim oldTable As Range, newTable As Range, i As Integer, j As Integer, m As Integer, n As Integer
Set oldTable = Application.InputBox(Prompt:="Please Select old values", Title:="Range Select", Type:=8)
Set newTable = Application.InputBox(Prompt:="Please Select new values", Title:="Range Select", Type:=8)
i = oldTable.Rows.Count
j = oldTable.Columns.Count
For m = 1 To i
For n = 1 To j
If oldTable.Cells(i, j) = newTable.Cells(i, j) Then
newTable.Cells(i, j).Interior.ColorIndex = 6
Else
newTable.Cells(i, j).Interior.ColorIndex = 3
End If
Next n
Next m
End Sub
它更加高效的使用條件格式,可以直接在Excel或從VBA模塊。在後一種情況下,Jeeped會回覆一個相當新穎的帖子,它會讓你走上正確的道路 – user3598756