Compare 2 lists from 2 different worksheets

Flavien

Board Regular
Joined
Jan 8, 2023
Messages
54
Office Version
  1. 365
Platform
  1. Windows
Hello!

I would like to compare 2 lists that contain file numbers all named P1234-A or P12345-A (one letter, 4 or 5 digits, one letter). I would like to compare 2 lists that contain file numbers all named P1234-A or P12345-A (one letter, 4 or 5 digits, one letter). The first list is exhaustive, it contains all the file numbers Up to date.

In the second list many file numbers are missing, or are too old. Only the final letter can change.

I would like to make a macro that would allow me to compare these 2 lists by telling me if the file numbers match or not or if the number does not exist.

I have not found anything on the site that I know how to exploit. Do you have an idea? Can you help me?

Thank you fort time and your help.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Please provide with XL2BB (no pictures) of your sample worksheet and a mocked up solution.
 
Upvote 0
Hello,
I would like to compare the lists in D&E columns. D is my exhaustive list (well normally) if however a data from column E does not exist in column D, I would like the transferred data to be highlighted in yellow. In addition, the macro does not remove duplicates.

Do you have idea to delete duplicates and highlight added datas?

Thanks

Classeur1
ABCDEF
1liste ERPLise GCU
21001 - A1002 - B
31002 - B1003 - C
41003 - C1004 - D
51004 - D1006 - A
61005 - E1007 - B
71006 - A1008 - C
81007 - B1009 - A
91008 - C1010 - B
101009 - A1011 - A
111010 - B1012 - B
121011 - A1014 - D
131012 - B1015 - E
141013 - C1016 - A
151011-A
161011-B
171014-A
181002 - B
191003 - C
201004 - D
211006 - A
221007 - B
231008 - C
241009 - A
251010 - B
261011 - A
271012 - B
281014 - D
291015 - E
301016 - A
311011-A
321011-B
331014-A
341002 - B
351003 - C
361004 - D
371006 - A
381007 - B
391008 - C
401009 - A
411010 - B
421011 - A
431012 - B
441014 - D
451015 - E
461016 - A
471011-A
481011-B
491014-A
50
Feuil1


Classeur1
AB
1liste ERPLise GCU
21001 - A
31002 - B1002 - B
41002 - B1002 - B
51002 - B1002 - B
61003 - C1003 - C
71003 - C1003 - C
81003 - C1003 - C
91004 - D1004 - D
101004 - D1004 - D
111004 - D1004 - D
121005 - E
131006 - A1006 - A
141006 - A1006 - A
151006 - A1006 - A
161007 - B1007 - B
171007 - B1007 - B
181007 - B1007 - B
191008 - C1008 - C
201008 - C1008 - C
211008 - C1008 - C
221009 - A1009 - A
231009 - A1009 - A
241009 - A1009 - A
251010 - B1010 - B
261010 - B1010 - B
271010 - B1010 - B
281011 - A1011 - A
291011 - A1011 - A
301011 - A1011 - A
311011-A1011-A
321011-A1011-A
331011-A1011-A
341011-B1011-B
351011-B1011-B
361011-B1011-B
371012 - B1012 - B
381012 - B1012 - B
391012 - B1012 - B
401013 - C
411014 - D1014 - D
421014 - D1014 - D
431014 - D1014 - D
441014-A1014-A
451014-A1014-A
461014-A1014-A
471015 - E1015 - E
481015 - E1015 - E
491015 - E1015 - E
501016 - A1016 - A
511016 - A1016 - A
521016 - A1016 - A
53
Feuil16
 
Upvote 0
Below the macro used:

Sub comparerlistes()
Dim MasterListRange As Range
Dim WeeklyListRange As Range
Dim vMaster As Variant
Dim vWeek As Variant
Dim MasterListRows As Long
Dim WeeklyListRows As Long
Dim vR() As Variant
Dim i As Long, n As Long, j As Long
Dim isExist As Boolean
Dim Ws As Worksheet

MasterListRows = Sheets("Feuil1").Cells(Rows.Count, 4).End(xlUp).Row '<~~ Correct column number
WeeklyListRows = Sheets("Feuil1").Cells(Rows.Count, 5).End(xlUp).Row '<~~ Correct column number

Set MasterListRange = Sheets("Feuil1").Range("D2:D" & MasterListRows)
Set WeeklyListRange = Sheets("Feuil1").Range("E2:E" & WeeklyListRows)

vMaster = MasterListRange
vWeek = WeeklyListRange

For i = 1 To UBound(vWeek, 1)
If WorksheetFunction.CountIf(MasterListRange, UCase(vWeek(i, 1))) Then
n = n + 1
ReDim Preserve vR(1 To 2, 1 To n)
vR(1, n) = UCase(vWeek(i, 1))
vR(2, n) = vWeek(i, 1)
Else
n = n + 1
ReDim Preserve vR(1 To 2, 1 To n)
vR(1, n) = UCase(vWeek(i, 1))
vR(2, n) = vWeek(i, 1)
End If
Next i
For j = 1 To UBound(vMaster, 1)
isExist = False
For i = 1 To UBound(vWeek, 1)
If vMaster(j, 1) = UCase(vWeek(i, 1)) Then
isExist = True
Exit For
End If
Next i
If Not isExist Then
n = n + 1
ReDim Preserve vR(1 To 2, 1 To n)
vR(1, n) = vMaster(j, 1)
End If
Next j
Set Ws = Sheets.Add '<~~ Sheets("Your seetname")
With Ws
.Range("a1").Resize(1, 2) = Sheets("Feuil1").Range("d1").Resize(1, 2).Value
.Range("a2").Resize(n, 2) = WorksheetFunction.Transpose(vR)
.Range("a1").CurrentRegion.Sort .Range("a1"), xlAscending, Header:=xlYes
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,194
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top