Combining data from 2 columns if they match each other

fsanjaya

New Member
Joined
Aug 8, 2023
Messages
7
Office Version
  1. 2019
Platform
  1. Windows
Hello, I was wondering if anyone knows how to combine data from 2 separate columns into a new column only if they match each other? Attached below is a sample:
1692085116093.png

A and B are the 2 columns and C is the column containing the combined data.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
This, perhaps?
Book16
ABC
1ABC
211
311
411
52 
63 
744
844
Sheet1
Cell Formulas
RangeFormula
C2:C8C2=IF(COUNTIF($A$2:$A$8,$B2),$B2,IF(COUNTIF($B$2:$B$8,$A2),$A2,""))
 
Upvote 0
This, perhaps?
Book16
ABC
1ABC
211
311
411
52 
63 
744
844
Sheet1
Cell Formulas
RangeFormula
C2:C8C2=IF(COUNTIF($A$2:$A$8,$B2),$B2,IF(COUNTIF($B$2:$B$8,$A2),$A2,""))
Hi! I tried out your formula (adjusted to the sheet I have) but it only shows me numbers from the 2nd column for some reason; for better representation, my data looks more like this:
1692122159255.png

Could it be that the formula doesn't work on the above data set because of the spaces in between 2 duplicates?
 
Upvote 0
Perhaps I am misinterpreting what you want. When you say "only if they match each other", I have interpreted that to mean that if a value in column B can be found in column A, or if a value in column A can be found in column B, put it in column C.

If you mean that to put a value in column C if it appears more than once in either column A or B, try
Excel Formula:
=IF(OR(COUNTIF($A$2:$B$40,A2:B2)>1),CONCAT(A2:B2),"")
 
Upvote 0
Perhaps I am misinterpreting what you want. When you say "only if they match each other", I have interpreted that to mean that if a value in column B can be found in column A, or if a value in column A can be found in column B, put it in column C.

If you mean that to put a value in column C if it appears more than once in either column A or B, try
Excel Formula:
=IF(OR(COUNTIF($A$2:$B$40,A2:B2)>1),CONCAT(A2:B2),"")
Your initial interpretation is correct! If the number appears in both columns, I want to include all the instances it appears in both columns in the combined data column. 184 appears in both columns and so the 2 instances it appears in column 2 and the 1 instance it appears in column 1 are included in the combined data column. When I tested out the formula however, I keep getting numbers 185, 188, and 190 in the combined data column even though they aren't listed in the 2nd column. Sorry for the confusion!
 
Upvote 0
So since 185, 188 and 190 aren't appearing in your image... the initial formula was correct after all?
 
Upvote 0
So since 185, 188 and 190 aren't appearing in your image... the initial formula was correct after all?
The combined data column in the second image I sent is what it should've looked like (I did that manually for representation of the result I want), so yes, the first formula should've been correct, but this is what I'm getting when I apply the first formula to my data set:
1692162813046.png

The formula inserted into the formula bar: =IF(COUNTIF($CJ$2:$CJ$40,$CK2),$CK2,IF(COUNTIF($CK$2:$CK$40,$CJ2),$CJ2,""))
 
Upvote 0
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,689
Members
449,117
Latest member
Aaagu

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