Extract common numbers

BenElliott

Board Regular
Joined
Jul 19, 2012
Messages
144
I'm trying to compare two columns of numbers and extract the numbers that are common to both.

Cell A2 contains the number of filled cells in column 'A'. Column 'B' has list 2.

I can use the following to extract the numbers but it leaves blank cells in the resultant column 'C': =IF(ISERROR(MATCH(A5,$D$5:$D$200,0)),"",A5)

If I use the following:=IF(ROWS(A$5:A5)>$A$2,"",INDEX($D$5:$D$200,AGGREGATE(15,6,(ROW($B$5:$B$200)-ROW($B$5)+1)/ISNUMBER(MATCH($B$5:$B$200,$A$5:$A$200,0)),ROWS($E$5:E5)))) I get the first common value in every cell of column 'C'

My head is spinning. Where am I going wrong?

Thanks for your patience.

Ben
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
A small data sample (~10 rows) along with expected results would be helpful.

M.
 
Upvote 0
If the columns have the same header you can use one as a criteria range for an AdvanceFilter on the other column.
 
Last edited:
Upvote 0
I'm s
Sorry, Marcelo. This shows how mushy my brain is this evening. The table below shows part of my two lists in Columns 'A' and 'B'. A I mentioned in my original question, cell A2 is the count of the data in Column 'A'. The full possible list extends over rows 5-200. I am trying to find the common numbers in 'A' and 'B' and put the result in Column 'C'

A
B
C
Count of Col 'A'
1
62
36
89
2
82
89
145
3
83
99
4
89
40
5
91
145
6
111
187
7
136
50
8
137
9
145
10
151
11
162

<tbody>
</tbody>
 
Upvote 0
just for fun ;)

With PowerQuery

ABC
62​
36​
89​
82​
89​
145​
83​
99​
89​
40​
91​
145​
111​
187​
136​
50​
137​
145​
151​
162​

Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Added Custom1" = Table.AddColumn(Table.ExpandTableColumn(Table.AddColumn(Source, "Custom", each Table2), "Custom", {"B"}, {"B"}), "Custom", each [A]=[B]),
    #"Renamed Columns" = Table.RenameColumns(Table.SelectColumns(Table.SelectRows(#"Added Custom1", each ([Custom] = true)),{"A"}),{{"A", "C"}})
in
    #"Renamed Columns"[/SIZE]
 
Last edited:
Upvote 0
Thanks, Mike.

I am aware I can use Advance filter but I need to do this through Array formulae because of everything else that is going on in the workbook, hence my formulae in my original question.
 
Upvote 0
Try:
Excel Workbook
ABC
1623689
28289145
38399
48940
591145
6111187
713650
8137
9145
10151
11162
Sheet
 
Upvote 0
Using your data sample in post 5


A
B
C
1
Count​
2
2​
3
4
5
82​
36​
89​
6
83​
89​
145​
7
89​
99​
8
91​
40​
9
111​
145​
10
136​
187​
11
137​
50​
12
145​
13
151​
14
162​
15

Formula in A2 (qty of numbers in A5:A200 present in B5:B200)
=SUMPRODUCT(--ISNUMBER(MATCH(A$5:A$200,B$5:B$200,0)))

Formula in C5 copied down
=IF(ROWS(C$5:C5)>A$2,"",INDEX(A$5:A$200,AGGREGATE(15,6,(ROW(A$5:A$200)-ROW(A$5)+1)/ISNUMBER(MATCH(A$5:A$200,B$5:B$200,0)),ROWS(C$5:C5))))

M.
 
Upvote 0
A different ibterpretation…


Book1
DEF
1Count
22
3
4#list#
5823689
68389145
78999
814540
991145
10111187
1113650
12137
13145
1489
15162
Sheet1


In D2 control+shift+enter, not just enter:

=SUM(IF(FREQUENCY(IF(ISNUMBER(MATCH($D$5:$D$15,$E$5:$E$11,0)),$D$5:$D$15),$D$5:$D$15),1))

In F5 control+shift+enter, not just enter, and copy down:

=IF(ROWS($F$5:F5)>$D$2,"",MIN(IF(ISNUMBER(MATCH($D$5:$D$15,$E$5:$E$11,0)),IF(ISNA(MATCH($D$5:$D$15,$F$4:F4,0)),$D$5:$D$15))))
 
Upvote 0

Forum statistics

Threads
1,214,618
Messages
6,120,544
Members
448,970
Latest member
kennimack

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