Multiple cell reference/Address for matching values in two columns using address & Match formula

confused_09

New Member
Joined
Aug 22, 2012
Messages
4
I have a sheet where in Column A1:A1001 there is a list of numbers, similarly in column B1:B1001 there is another list of numbers. I wish to see which of the numbers in Column A are there in Column B and then have the absolute cell address / reference of these matching numbers present in column B. I used this formula in C1 (=ADDRESS(MATCH(A1,$B$1:$B$1001,0),2,1,1) )
and filled in the rest of the rows till C1001, so that i can have the cell reference of matching number in Column B in the same row as the Column A number for which i am searching the match in column B.

I am getting the cell reference in column C only for the first match, not for the subsequent matches, how can I have all the cell references where this match is occurring?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi and welcome to Mr Excel Forum

Your formula worked for me
[TABLE="width: 144"]
<COLGROUP><COL style="WIDTH: 48pt" span=3 width=64><TBODY>[TR]
[TD="class: xl63, width: 64, bgcolor: transparent, align: right"]3[/TD]
[TD="class: xl63, width: 64, bgcolor: transparent, align: right"]4[/TD]
[TD="class: xl63, width: 64, bgcolor: transparent"]$B$2[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: transparent, align: right"]5[/TD]
[TD="class: xl63, bgcolor: transparent, align: right"]3[/TD]
[TD="class: xl63, bgcolor: transparent"]$B$3[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: transparent, align: right"]10[/TD]
[TD="class: xl63, bgcolor: transparent, align: right"]5[/TD]
[TD="class: xl63, bgcolor: transparent"]$B$4[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: transparent, align: right"]4[/TD]
[TD="class: xl63, bgcolor: transparent, align: right"]10[/TD]
[TD="class: xl63, bgcolor: transparent"]$B$1[/TD]
[/TR]
</TBODY>[/TABLE]


M.
 
Upvote 0
Thanks for your reply.

I would like to have results as in the column "expected results" in following table rather than the column "actual results"


Col A Col B Actual Result Expected result
3 4 $B$2 $B$2, $B$5, $B$6
5 3 $B$3 $B$3, $B$7
10 5 $B$4 $B$4
4 10 $B$1 $B$1
2 3 #N/A #N/A
1 3 #N/A #N/A
5 5 $B$4 $B$3, $B$7

As you will notice that the current formula gives cell reference for the first match, not the subsequent ones...



Hi and welcome to Mr Excel Forum

Your formula worked for me
[TABLE="width: 144"]
<tbody>[TR]
[TD="class: xl63, width: 64, bgcolor: transparent, align: right"]3[/TD]
[TD="class: xl63, width: 64, bgcolor: transparent, align: right"]4[/TD]
[TD="class: xl63, width: 64, bgcolor: transparent"]$B$2[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: transparent, align: right"]5[/TD]
[TD="class: xl63, bgcolor: transparent, align: right"]3[/TD]
[TD="class: xl63, bgcolor: transparent"]$B$3[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: transparent, align: right"]10[/TD]
[TD="class: xl63, bgcolor: transparent, align: right"]5[/TD]
[TD="class: xl63, bgcolor: transparent"]$B$4[/TD]
[/TR]
[TR]
[TD="class: xl63, bgcolor: transparent, align: right"]4[/TD]
[TD="class: xl63, bgcolor: transparent, align: right"]10[/TD]
[TD="class: xl63, bgcolor: transparent"]$B$1
[/TD]
[/TR]
</tbody>[/TABLE]


M.
 
Upvote 0
Thanks for your reply.

I would like to have results as in the column "expected results" in following table rather than the column "actual results"


[TABLE="class: outer_border, width: 500, align: left"]
<tbody>[TR]
[TD]Col A[/TD]
[TD]Col B[/TD]
[TD]Actual Results[/TD]
[TD]Expected results[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]4[/TD]
[TD]$B$2[/TD]
[TD]$B$2, $B$5, $B$6[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]3[/TD]
[TD]$B$3[/TD]
[TD]$B$3, $B$7[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]5[/TD]
[TD]$B$4[/TD]
[TD]$B$4[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]10[/TD]
[TD]$B$1[/TD]
[TD]$B$1[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]3[/TD]
[TD]#N/A[/TD]
[TD]#N/A[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]3[/TD]
[TD]#N/A[/TD]
[TD]#N/A[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]5[/TD]
[TD]$B$3[/TD]
[TD]$B$3, $B$7[/TD]
[/TR]
</tbody>[/TABLE]














As you will notice that the current formula gives cell reference for the first match, not the subsequent ones...
 
Upvote 0
Try this

Alt+F11 to open the VBEditor

go to Insert > Module

paste the code below (User Defined Function) in the right-panel

Code:
Function aconcat(a As Variant, Optional sep As String = "") As String
' Harlan Grove, Mar 2002
    Dim y As Variant
    If TypeOf a Is Range Then
        For Each y In a.Cells
            aconcat = aconcat & y.Value & sep
        Next y
    ElseIf IsArray(a) Then
        For Each y In a
            aconcat = aconcat & y & sep
        Next y
    Else
        aconcat = aconcat & a & sep
    End If
    aconcat = Left(aconcat, Len(aconcat) - Len(sep))
End Function

Back to Excel

in D1 insert this array formula
=IF(COUNTIF($B$1:$B$1001,A1),SUBSTITUTE(Aconcat(IF($B$1:$B$1001=A1,", "&ADDRESS(ROW($B$1:$B$1001),2),"")),", ","",1),NA())

confirmed with Ctrl+Shift+Enter
(hold down both Ctrl and Shift keys and hit Enter)

copy down

M.
 
Upvote 0
Thank you so much, i had almost given up on this.

I do not understand VBA/UDF, however would want to know what is this UDF doing here to spin this magic? It would be great if you can briefly explain what this UDF aconcat is doing?

Thanks a lot once more.
 
Upvote 0
Thank you so much, i had almost given up on this.

I do not understand VBA/UDF, however would want to know what is this UDF doing here to spin this magic? It would be great if you can briefly explain what this UDF aconcat is doing?

Thanks a lot once more.

You are very welcome and thanks for the feedback!

Excel has not a built-in function to concatenate values in an array or range.
The UDF aconcat does it!

In this specific situation an array is produced by this part of the formula
IF($B$1:$B$1001=A1,", "&ADDRESS(ROW($B$1:$B$1001),2),"")

For example, using your data sample in #4, for the first row, where A1=3, the array produced is - note the concatenation ", "&ADDRESS(ROW...)
{"";", $B$2";"";"";", $B$5";", $B$6";""}

Then the aconcat function concatenates these values producing the string
", $B$2, $B$5, $B$6"

At last, the SUBSTITUTE function substitutes the first instance of ", " for "" (empty string) resulting in
$B$2, $B$5, $B$6

That's it!

Hope i made myself clear.

M.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

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