Trying to match 2 arrays using VBA please help

TeckTeck

New Member
Joined
Sep 28, 2023
Messages
15
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi anyone, I would like to match this 2 table as shown:

Screenshot 2023-09-28 at 11.59.58 PM.png


Using the reference list, match the master list and return Column D to Column G. However the placement of the return has to be of the same position as the master list.

Condition 1: If the code number of the reference list (Column D) matches the code number of the master list (Column A) then paste Column D in the same placement as Column A in a new column (Column G)

Condition 2: If the Name of the reference list (Column E) matches partially or completely to the name of the master list (Column B) then paste Column D in the same placement as Column A in a new column (Column G)

I am aware and tried VLOOKUP or Using wildcards ("*") but could not do it. I am hoping someone has done it before and can share with me the VBA codes for this type of situation. Thank you.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I would have a macro that will make all the Names the same.
It would mean making a onetime list for comparison.
That list could be in a hidden sheet if you want to.
I can see your Material Balance being called "Mat Bal", "Material Bal", "Mat Balance" and maybe another several possibilities let alone Capitals and Small letters like you have in the last entry in Column B.
 
Upvote 0
Which Column would be the "Master" Column?
Do you want the data in Column E to be changed to the text in Column A or the other way around?
 
Upvote 0
Is it possible for the text in column E to partially and completely match different cell text in column B? like this:

TeckTeck 1.xlsm
ABCDEFG
2Code NumberNameCode NumberNameCode Number
36705Instrumentation Pressure Relief603Pressure Relief
41750Pressure Relief
Sheet2
 
Upvote 0
Which Column would be the "Master" Column?
Do you want the data in Column E to be changed to the text in Column A or the other way around?
Hi after comparing the reference list to the master list (for both text and/or code number)

i would need the reference list code number (column D) to be pasted onto a new column, however, the pasted code number should be on the same row as the master list that was matched.
 
Upvote 0
Is it possible for the text in column E to partially and completely match different cell text in column B? like this:

TeckTeck 1.xlsm
ABCDEFG
2Code NumberNameCode NumberNameCode Number
36705Instrumentation Pressure Relief603Pressure Relief
41750Pressure Relief
Sheet2

Hi, yes however is it possible to paste D3 into G4 as it must match the row of column A/B.

So G3 would appear blank and G4 would appear as "603"
 
Upvote 0
Sorry, I misunderstood your data. After reading your example again, I don't think the partial match will work. Excel functions can't recognize 'Mat Bal' as a partial match for 'Material Balance'. So, I can't help you. I hope what @jolivanes suggested in post #2 would work.
 
Upvote 0
This method has it's flaws as many will, i have used this method before to match data, it may not work for you but will share anyway. This method required VBA as well as Formulae:

Book1
ABCDEFG
1Master ListReference ListNew Code from Column E with Reference to Master List S/N
2Code NumberNameCode NumberNameCode Number
36705Material Balance1Piping Instrument Diagram3
41750Plot Plan2Instrumenation Pressure 
5135Statistic with Anova3Mat Bal 
62000Heat and Mass4Engineering Control Design 
77884Piping Diagram5Pressure Relief1
83270Process Flow 
98783Basis of Design 
101007Pressure Relief5
113040Instrumentation Pressure Safety2
128137Engineering and Control4
Sheet1
Cell Formulas
RangeFormula
G3:G12G3=LET( lv,--BYROW($E$3:$E$7,LAMBDA(x,IF(ISNUMBER(SEARCH(LEFT(x,3),B3)),LevenshteinDistance(B3,x),100))), f,FILTER($D$3:$D$7,lv=MIN(lv)), IF(COUNTA(f)=1,f,"") )


Code Used:
VBA Code:
Function LevenshteinDistance(s1 As String, s2 As String) As Integer
    Dim len1 As Integer
    Dim len2 As Integer
    Dim d() As Integer
    Dim i As Integer
    Dim j As Integer
    
    len1 = Len(s1)
    len2 = Len(s2)
    
    ReDim d(0 To len1, 0 To len2)
    
    For i = 0 To len1
        d(i, 0) = i
    Next i
    
    For j = 0 To len2
        d(0, j) = j
    Next j
    
    For i = 1 To len1
        For j = 1 To len2
            If Mid(s1, i, 1) = Mid(s2, j, 1) Then
                d(i, j) = d(i - 1, j - 1)
            Else
                d(i, j) = Application.Min(d(i - 1, j) + 1, d(i, j - 1) + 1, d(i - 1, j - 1) + 1)
            End If
        Next j
    Next i

    LevenshteinDistance = d(len1, len2)
End Function
 
Upvote 0

Forum statistics

Threads
1,224,734
Messages
6,180,630
Members
452,991
Latest member
JM_000888

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