A variation on the compare 2 columns in Excel
Solved/Closed
BrianGreen
Posts
1005
Registration date
Saturday January 17, 2015
Status
Moderator
Last seen
September 30, 2021
-
Apr 12, 2016 at 06:49 PM
BrianGreen Posts 1005 Registration date Saturday January 17, 2015 Status Moderator Last seen September 30, 2021 - Apr 13, 2016 at 06:32 PM
BrianGreen Posts 1005 Registration date Saturday January 17, 2015 Status Moderator Last seen September 30, 2021 - Apr 13, 2016 at 06:32 PM
Related:
- A variation on the compare 2 columns in Excel
- Tentacle locker 2 - Download - Adult games
- Five nights in anime 2 - Download - Adult games
- Feeding frenzy 2 download - Download - Arcade
- Euro truck simulator 2 download free full version pc - Download - Simulation
- The grim reaper 2 apk - Download - Adult games
1 response
Brian,
Try this for starters. It should be pretty easy to follow.
It goes down List1 and tries to find a match with values in List2, highlighting accordingly.
Values in List2 that are NOT in List1 remain unchanged.
Try this for starters. It should be pretty easy to follow.
It goes down List1 and tries to find a match with values in List2, highlighting accordingly.
Values in List2 that are NOT in List1 remain unchanged.
Sub diff() LR_List1 = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row LR_List2 = ActiveSheet.Range("B" & Rows.Count).End(xlUp).Row For n = 2 To LR_List1 myvalue1 = Cells(n, 1).Value Match = False For m = 2 To LR_List2 myvalue2 = Cells(m, 2).Value If myvalue1 = myvalue2 Then Cells(n, 1).Interior.ColorIndex = 4 'Green Cells(m, 2).Interior.ColorIndex = 4 'Green Match = True End If Next m If Match = False Then Cells(n, 1).Interior.ColorIndex = 3 ' Red End If Next n End Sub
Apr 13, 2016 at 06:32 PM
This worked just as you said it would when I was at home with some made up lists.
I have tweeked it a little to mark all of list 2 as red to start with (thus any that are red at the end are not in list 1 either).
I have offset the highlighting by one cell to the right to take account of the conditional formatting to highlight the duplicate values. This means that the columns defined in lines 3, 9, and 12 have had to be changed to make room for this.
I have also saved a little processing time by if it sees a blank cell in list 1 then it doesnt do any checks but instead leaves the cell unhighlighted and moves to the next cell in list 1. At the end it also does does a search on list 2 to mark any empty cells as not filled.
When I am in the real working environment with real values I will test it again and post the final code I have in an effort to help anyone else with this sort of problem.
Thanks again Ray - I owe you another beer.