Beginer1026
New Member
- Joined
- Sep 29, 2022
- Messages
- 5
- Office Version
- 365
- Platform
- Windows
Hi,
How can I modify the code so that it can also compare columns C and H ("Nature") and highlight the difference (i.e. cell H4)...just like cell G10 and I15 ?
Thanks in advance !
How can I modify the code so that it can also compare columns C and H ("Nature") and highlight the difference (i.e. cell H4)...just like cell G10 and I15 ?
Compare and Find Differences.xlsm | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | |||
1 | Document No. | Amount | Nature | Company | Document No. | Amount | Nature | Company | ||||
2 | 220537-W | 13,999.50 | ABC | Company A | 220537-W | $13,999.50 | ABC | Company A | ||||
3 | 220538-W | 3,840.00 | XYZ | Company B | 220538-W | $3,840.00 | XYZ | Company B | ||||
4 | 220539-W | 1,597.00 | ABC | Company B | 220539-W | $1,597.00 | XYZ | Company B | ||||
5 | 220542-W | 810.69 | ZZZ | Company B | 220542-W | $810.69 | ZZZ | Company B | ||||
6 | 220543-W | 2,800.00 | ZZZ | Company B | 220543-C | $2,800.00 | ZZZ | Company B | ||||
7 | 220544-W | 604.06 | ZZZ | Company C | 220544-W | $604.06 | ZZZ | Company C | ||||
8 | 220547-W | 2,752.25 | XYZ | Company M | 220545-W | $40,046.40 | ZZZ | Company C | ||||
9 | 220611-C | 2,880.00 | ZZZ | Company GGG | 220546-W | $14,400.00 | XYZ | Company P | ||||
10 | 220612-W | 2,225.00 | ABC | Company EGG | 220547-W | $2,752.28 | XYZ | Company M | ||||
11 | 220548-C | $500.00 | XYZ | Company BBC | ||||||||
12 | 220549-C | $1,920.00 | XYZ | Company RET | ||||||||
13 | 220609-C | $4,960.00 | XYZ | Company KL | ||||||||
14 | 220610-C | $3,594.88 | XYZ | Company MBC | ||||||||
15 | 220611-C | $2,880.00 | ZZZ | Company DGG | ||||||||
16 | 220612-W | $2,225.00 | ABC | Company EGG | ||||||||
17 | ||||||||||||
Sheet1 |
VBA Code:
Sub CompareList()
Application.ScreenUpdating = True
Dim DocNo As Range
Dim RngList As Object
Dim rng As Range
Set RngList = CreateObject("Scripting.Dictionary")
Dim FoundDocNo As Range
Dim LastRow2 As Long
Dim lastRow As Long
lastRow = Sheets("Sheet1").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For Each DocNo In Sheets("Sheet1").Range("F2:F" & lastRow)
Set FoundDocNo = Sheets("Sheet1").Range("A:A").Find(DocNo, LookIn:=xlValues, lookat:=xlWhole)
If Not FoundDocNo Is Nothing Then
For Each rng In Sheets("Sheet1").Range("A" & FoundDocNo.Row & ":D" & FoundDocNo.Row)
If Not RngList.Exists(rng.Value) Then
RngList.Add rng.Value, Nothing
End If
Next rng
For Each rng In Sheets("Sheet1").Range("F" & DocNo.Row & ":I" & DocNo.Row)
If Not RngList.Exists(rng.Value) Then
rng.Interior.ColorIndex = 6
End If
Next rng
Else
With Sheets("Sheet1").Range("F" & DocNo.Row & ":I" & DocNo.Row)
.Interior.ColorIndex = 4
End With
' DocNo.Interior.ColorIndex = 4
End If
Next DocNo
LastRow2 = Sheets("Sheet1").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For Each DocNo In Sheets("Sheet1").Range("a2:a" & lastRow)
Set FoundDocNo = Sheets("Sheet1").Range("f:f").Find(DocNo, LookIn:=xlValues, lookat:=xlWhole)
If FoundDocNo Is Nothing Then
With Sheets("Sheet1").Range("A" & DocNo.Row & ":D" & DocNo.Row)
.Interior.ColorIndex = 8
End With
' DocNo.Interior.ColorIndex = 8
End If
Next DocNo
End Sub
Thanks in advance !