Compare Two Lists

nniedzielski

Well-known Member
Joined
Jan 8, 2016
Messages
598
Office Version
  1. 2019
Platform
  1. Windows
I am using V Lookup to compare two lists:

VBA Code:
Range("D2").Formula = "=VLOOKUP(B2,'Yard Check'!A:C,3,FALSE)"

I am having a few issues with the comparing of the lists, I have two lists where sometimes the trailer numbers can vary enough to throw off the formula, and I'm wondering how I can code so the Macro finds the trailers to be the same:

Examples:

List A List B
C53106 53106
E001 1
JM122 122
58672S 58672
UMXU830389 830389

Right now when we run the VLookup its returning #N/A, but they are actually the same, how can I get excel VBA to recognize that these are the same? I have tried using "True" instead of "False" but found that didn't really solve the problem.

thank you,
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
What do you have in B2?

And what values do you have in column A of the "Yard Check" sheet?
 
Upvote 0
B2 is list A, Column A is list B.

They got kind of jammed together when i submitted the post,
 
Upvote 0
I did not understand.
Do you want to find this data C53106 in the following list?

Book1
A
1
253106
31
4122
558672
6830389
Yard Check


--------------------------------------------------------------

Or Do you want to find this data 53106 in the following list?

Book1
AB
1
2C53106
3E001
4JM122
558672S
6UMXU830389
Hoja2
 
Upvote 0
If you were to put in C2 on Hoja2, a Vlookup comparing B2 on Hoja 2 to A2 on Yard Check, that it returns something other than #N/A.

does that help at all?
 
Upvote 0
Try this

VBA Code:
Sub compareLists()
    Range("D2").FormulaArray = _
        "=INDEX('Yard Check'!$C$2:$C$6," & _
        "SUMPRODUCT((IF(--ISNUMBER(FIND('Yard Check'!$A$2:$A$6,B2))," & _
        "LEN('Yard Check'!$A$2:$A$6))=(MAX(IF(--ISNUMBER(FIND('Yard Check'!$A$2:$A$6,B2))," & _
        "LEN('Yard Check'!$A$2:$A$6)))))*(ROW('Yard Check'!$A$2:$A$6)))-1)"
End Sub
 
Upvote 0
This did not work, simply got a #VALUE!

1574713491382.png


However, i am not 100% you understand what i am trying to do.
 
Upvote 0
I guess you have something like this in the "Yard Check" sheet

Book1
ABC
1
253106data2value2
31data3value3
4122data4value4
558672data5value5
6830389data6value6
Yard Check



I also assume that on sheet2 you have something like this.
Book1
ABCD
1
2C53106
3E001
4JM122
558672S
6UMXU830389
Sheet2


If you run the macro on sheet2 the result will be like this:
Book1
ABCD
1
2C53106value2
3E001
4JM122
558672S
6UMXU830389
Sheet2
Cell Formulas
RangeFormula
D2D2{=INDEX('Yard Check'!$C$2:$C$6,SUMPRODUCT((IF(--ISNUMBER(FIND('Yard Check'!$A$2:$A$6,B2)),LEN('Yard Check'!$A$2:$A$6))=(MAX(IF(--ISNUMBER(FIND('Yard Check'!$A$2:$A$6,B2)),LEN('Yard Check'!$A$2:$A$6)))))*(ROW('Yard Check'!$A$2:$A$6)))-1)}
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0
OK, I was able to make it work recreating the sheets you have above, so thats awesome, thank you.

Now, i need to be able to take this formula and make it work for my workbook. My Yard Check list is Column A, and it can vary in size.
 
Upvote 0
Try this

VBA Code:
Sub compareLists()
  Dim lr As Long, sh As Worksheet, cad1 As String, cad2 As String
  Set sh = Sheets("Yard Check")
  lr = sh.Range("A" & Rows.Count).End(xlUp).Row
  cad1 = "'" & sh.Name & "'!" & sh.Range("$C$2:$C$" & lr).Address
  cad2 = "'" & sh.Name & "'!" & sh.Range("$A$2:$A$" & lr).Address
  Range("D2").FormulaArray = _
    Replace(Replace("=INDEX(#,SUMPRODUCT((IF(--ISNUMBER(FIND(@,B2))," & _
    "LEN(@))=(MAX(IF(--ISNUMBER(FIND(@,B2)),LEN(@)))))*(ROW(@)))-1)", "#", cad1), "@", cad2)
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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