Comparing columns of data between worksheets and returning value when matched.

Ronanm

Board Regular
Joined
Nov 13, 2010
Messages
107
If I had three columns in one worksheet and three columns in another worksheet to compare. How can I check the 2nd worksheet to find matching records to the 1st worksheet, then pull out the fourth column value of the 2nd worksheet when there's a match?

Ideally with codeor array rather than concatenating and using Vlookups as there would be thousands of records. Thanks

<!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:AllowPNG/> </o:OfficeDocumentSettings> </xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:PunctuationKerning/> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-GB</w:LidThemeOther> <w:LidThemeAsian>X-NONE</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:EnableOpenTypeKerning/> <w:DontFlipMirrorIndents/> <w:OverrideTableStyleHps/> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="--"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true" DefSemiHidden="true" DefQFormat="false" DefPriority="99" LatentStyleCount="267"> <w:LsdException Locked="false" Priority="0" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Normal"/> <w:LsdException Locked="false" Priority="9" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="heading 1"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/> <w:LsdException Locked="false" Priority="39" Name="toc 1"/> <w:LsdException Locked="false" Priority="39" Name="toc 2"/> <w:LsdException Locked="false" Priority="39" Name="toc 3"/> <w:LsdException Locked="false" Priority="39" Name="toc 4"/> <w:LsdException Locked="false" Priority="39" Name="toc 5"/> <w:LsdException Locked="false" Priority="39" Name="toc 6"/> <w:LsdException Locked="false" Priority="39" Name="toc 7"/> <w:LsdException Locked="false" Priority="39" Name="toc 8"/> <w:LsdException Locked="false" Priority="39" Name="toc 9"/> <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/> <w:LsdException Locked="false" Priority="10" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Title"/> <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/> <w:LsdException Locked="false" Priority="11" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/> <w:LsdException Locked="false" Priority="22" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Strong"/> <w:LsdException Locked="false" Priority="20" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/> <w:LsdException Locked="false" Priority="59" SemiHidden="false" UnhideWhenUsed="false" Name="Table Grid"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/> <w:LsdException Locked="false" Priority="1" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 1"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 1"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 1"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/> <w:LsdException Locked="false" Priority="34" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/> <w:LsdException Locked="false" Priority="29" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Quote"/> <w:LsdException Locked="false" Priority="30" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 1"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 1"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 2"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 2"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 2"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 2"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 2"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 3"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 3"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 3"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 3"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 3"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 4"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 4"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 4"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 4"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 4"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 5"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 5"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 5"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 5"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 5"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 6"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 6"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 6"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 6"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 6"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/> <w:LsdException Locked="false" Priority="19" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/> <w:LsdException Locked="false" Priority="21" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/> <w:LsdException Locked="false" Priority="31" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/> <w:LsdException Locked="false" Priority="32" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/> <w:LsdException Locked="false" Priority="33" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Book Title"/> <w:LsdException Locked="false" Priority="37" Name="Bibliography"/> <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0cm; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-fareast-language:EN-US;} </style> <![endif]-->

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]FirstName
[/TD]
[TD]SecondName[/TD]
[TD]Dept[/TD]
[TD]FoundID[/TD]
[/TR]
[TR]
[TD]Paul[/TD]
[TD]Taylor[/TD]
[TD]Red[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Carol[/TD]
[TD]Jones[/TD]
[TD]Blue[/TD]
[TD]712[/TD]
[/TR]
</tbody>[/TABLE]


[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]FirstName
[/TD]
[TD]SecondName[/TD]
[TD]Dept[/TD]
[TD]ID[/TD]
[/TR]
[TR]
[TD]Bob[/TD]
[TD]Walker[/TD]
[TD]Yellow[/TD]
[TD]345[/TD]
[/TR]
[TR]
[TD]Carol[/TD]
[TD]Jones[/TD]
[TD]Blue[/TD]
[TD]712[/TD]
[/TR]
[TR]
[TD]Carol[/TD]
[TD]Jones[/TD]
[TD]Red[/TD]
[TD]999
[/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
using PowerQuery

[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#FFFFFF]Sources[/td][td][/td][td][/td][td][/td][td][/td][td=bgcolor:#FFFFFF]Result[/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#5B9BD5]FirstName[/td][td=bgcolor:#5B9BD5]SecondName[/td][td=bgcolor:#5B9BD5]Dept[/td][td][/td][td][/td][td=bgcolor:#70AD47]FirstName[/td][td=bgcolor:#70AD47]SecondName[/td][td=bgcolor:#70AD47]Dept[/td][td=bgcolor:#70AD47]ID[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Paul[/td][td=bgcolor:#DDEBF7]Taylor[/td][td=bgcolor:#DDEBF7]Red[/td][td][/td][td][/td][td=bgcolor:#E2EFDA]Carol[/td][td=bgcolor:#E2EFDA]Jones[/td][td=bgcolor:#E2EFDA]Blue[/td][td=bgcolor:#E2EFDA]
712​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Carol[/td][td]Jones[/td][td]Blue[/td][td][/td][td][/td][td]Paul[/td][td]Taylor[/td][td]Red[/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#5B9BD5]FirstName[/td][td=bgcolor:#5B9BD5]SecondName[/td][td=bgcolor:#5B9BD5]Dept[/td][td=bgcolor:#5B9BD5]ID[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Bob[/td][td=bgcolor:#DDEBF7]Walker[/td][td=bgcolor:#DDEBF7]Yellow[/td][td=bgcolor:#DDEBF7]
345​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td]Carol[/td][td]Jones[/td][td]Blue[/td][td]
712​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Carol[/td][td=bgcolor:#DDEBF7]Jones[/td][td=bgcolor:#DDEBF7]Red[/td][td=bgcolor:#DDEBF7]
999​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[/table]



Code:
[SIZE=1]// Merge1
let
    Source = Table.NestedJoin(Table1,{"FirstName", "SecondName", "Dept"},Table2,{"FirstName", "SecondName", "Dept"},"Table2",JoinKind.LeftOuter),
    Expand = Table.ExpandTableColumn(Source, "Table2", {"ID"}, {"ID"})
in
    Expand[/SIZE]
 
Last edited:
Upvote 0
VBA solution ;)

Using dictionary might be overkill here, but if there are thousand of entries, you don't want to make this kind of loops.

If you have any questions let me know

Code:
Sub FindMatch()
    
    Dim dic_One     As Object
    Dim dic_Result  As Object
    Dim wsOne       As Worksheet
    Dim wsTwo       As Worksheet
    Dim wsResult    As Worksheet
    Dim l_One       As Long
    Dim l_Two       As Long
    Dim l_Result    As Long
    Dim arr_One     As Variant
    Dim arr_Two     As Variant
    Dim str_Key     As String
    Dim v_Item      As Variant
    
    Set wsOne = ThisWorkbook.Sheets("One")
    Set wsTwo = ThisWorkbook.Sheets("Two")
    Set wsResult = ThisWorkbook.Sheets("Result")
    
    l_One = wsOne.Cells.Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    l_Two = wsTwo.Cells.Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    
    arr_One = wsOne.Range("A1:D" & l_One)
    arr_Two = wsTwo.Range("A1:D" & l_Two)
    
    Set dic_One = CreateObject("scripting.dictionary")
    Set dic_Result = CreateObject("scripting.dictionary")
    
    For l_One = LBound(arr_One, 1) To UBound(arr_One, 1)
        str_Key = arr_One(l_One, 1) & "||" & arr_One(l_One, 2) & "||" & arr_One(l_One, 3)
        dic_One(str_Key) = arr_One(l_One, 4)
    Next l_One
    
    For l_Two = LBound(arr_Two, 1) To UBound(arr_Two, 1)
        str_Key = arr_Two(l_Two, 1) & "||" & arr_Two(l_Two, 2) & "||" & arr_Two(l_Two, 3)
        If dic_One.exists(str_Key) Then
            dic_Result(str_Key) = arr_Two(l_Two, 4)
        End If
    Next l_Two
    
    For Each v_Item In dic_Result
        If Not v_Item = Empty Then
            l_Result = l_Result + 1
            
            wsResult.Range("A" & l_Result & ":C" & l_Result) = Split(v_Item, "||")
            wsResult.Range("D" & l_Result) = dic_Result(v_Item)
        End If
    Next v_Item
    
End Sub
 
Last edited:
Upvote 0
VBA solution ;)

Using dictionary might be overkill here, but if there are thousand of entries, you don't want to make this kind of loops.

If you have any questions let me know

Code:
Sub FindMatch()
    
    Dim dic_One     As Object
    Dim dic_Result  As Object
    Dim wsOne       As Worksheet
    Dim wsTwo       As Worksheet
    Dim wsResult    As Worksheet
    Dim l_One       As Long
    Dim l_Two       As Long
    Dim l_Result    As Long
    Dim arr_One     As Variant
    Dim arr_Two     As Variant
    Dim str_Key     As String
    Dim v_Item      As Variant
    
    Set wsOne = ThisWorkbook.Sheets("One")
    Set wsTwo = ThisWorkbook.Sheets("Two")
    Set wsResult = ThisWorkbook.Sheets("Result")
    
    l_One = wsOne.Cells.Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    l_Two = wsTwo.Cells.Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    
    arr_One = wsOne.Range("A1:D" & l_One)
    arr_Two = wsTwo.Range("A1:D" & l_Two)
    
    Set dic_One = CreateObject("scripting.dictionary")
    Set dic_Result = CreateObject("scripting.dictionary")
    
    For l_One = LBound(arr_One, 1) To UBound(arr_One, 1)
        str_Key = arr_One(l_One, 1) & "||" & arr_One(l_One, 2) & "||" & arr_One(l_One, 3)
        dic_One(str_Key) = arr_One(l_One, 4)
    Next l_One
    
    For l_Two = LBound(arr_Two, 1) To UBound(arr_Two, 1)
        str_Key = arr_Two(l_Two, 1) & "||" & arr_Two(l_Two, 2) & "||" & arr_Two(l_Two, 3)
        If dic_One.exists(str_Key) Then
            dic_Result(str_Key) = arr_Two(l_Two, 4)
        End If
    Next l_Two
    
    For Each v_Item In dic_Result
        If Not v_Item = Empty Then
            l_Result = l_Result + 1
            
            wsResult.Range("A" & l_Result & ":C" & l_Result) = Split(v_Item, "||")
            wsResult.Range("D" & l_Result) = dic_Result(v_Item)
        End If
    Next v_Item
    
End Sub

Thank you Skorpionkz. It will take a bit for me to understand it, but I am starting to learn about classes, collections and dictionaries so this will be great for me. Appreciate it.
BTW The result will go into the "Found" column as showing in the first table (It gets taken from the 4th Column in the second table. Thanks again...
 
Upvote 0
To have it in Found column code would need to be adjusted a little. It is almost 23pm for me now, let me know if you will figure out how to change the code so it give you result in requested column. If not I will update the code when I get to work and paste it.
 
Upvote 0
Bellow is updated code. Assumptions: first sheet is the source sheet, the second sheet is the sheet to populate with data.

Code:
Option Explicit


Sub FindMatch()
    
    Dim dic_One     As Object
    Dim wsOne       As Worksheet
    Dim wsTwo       As Worksheet
    Dim l_One       As Long
    Dim l_Two       As Long
    Dim l_Result    As Long
    Dim arr_One     As Variant
    Dim arr_Two     As Variant
    Dim arr_Result  As Variant
    Dim str_Key     As String
    
    Set wsOne = ThisWorkbook.Sheets("One")
    Set wsTwo = ThisWorkbook.Sheets("Two")
    
    l_One = wsOne.Cells.Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    l_Two = wsTwo.Cells.Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    
    arr_One = wsOne.Range("A1:D" & l_One)
    arr_Two = wsTwo.Range("A1:D" & l_Two)
    
    ReDim arr_Result(1 To l_Two, 1 To 1)
    
    
    Set dic_One = CreateObject("scripting.dictionary")
    
    For l_One = LBound(arr_One, 1) To UBound(arr_One, 1)
        str_Key = arr_One(l_One, 1) & "||" & arr_One(l_One, 2) & "||" & arr_One(l_One, 3)
        dic_One(str_Key) = arr_One(l_One, 4)
    Next l_One
    
    For l_Result = LBound(arr_Two, 1) To UBound(arr_Two, 1)
        str_Key = arr_Two(l_Result, 1) & "||" & arr_Two(l_Result, 2) & "||" & arr_Two(l_Result, 3)
        If dic_One.exists(str_Key) Then
            arr_Result(l_Result, 1) = dic_One(str_Key)
        End If
    Next l_Result
    
    arr_Result(1, 1) = "FoundID"
    wsTwo.Range("D1:D" & l_Two) = arr_Result


End Sub
 
Upvote 0
That works a treat Andrew. I'm going to wok through it and understand it as well. Thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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