Compare two columns

tugal

New Member
Joined
May 4, 2005
Messages
12
Hi

I wanted to compare two columns. If data from column A contains the same data in comlumn B then return A. And if column B contains the same data in column A then return B. In other words both columns should be compared and if there is a match located anywhere in that column then return that value.

Any thoughts? :p
Thanks
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Not sure what difference there is when comparing col A & B as you have described it. Can you provide an example of data and what you want the result to look like? Use Colo's HTMLmaker utility (see note at top of this forum).
 
Upvote 0
Maybe this will help
Book1
ABCD
1List 1List 2Return
2aaa
3bbb
4ccc
5dwd
6ex
7fd
8gz
Sheet1


Thanks
 
Upvote 0
So what you have described is that as long as columns A & B are the same it doesn't matter which you return in Col C but if they are different then you want the value from col A returned in Col C? DO I have that right? If so, then you just want col A returned all the time. So just copy col A into Col C. Look at your example again.
 
Upvote 0
I guess I'm not explaining this the right way. If the value matches in both column a and b then return that value in column C. If it doesn't not match in both columns then return nothing.
 
Upvote 0
In Cell "C2" put in the following formula and copy it on down.

=IF(A2=B2,B2,"")


Note: Your example in Cell "C5" shows a "d" when it should probably be blank.
 
Upvote 0
No that was purposely done to show my example. Cell "C5" shows a "d" because it exists in Column B just not in the same order as it does in Column A. That's where my problem lies.
 
Upvote 0
tugal said:
No that was purposely done to show my example. Cell "C5" shows a "d" because it exists in Column B just not in the same order as it does in Column A. That's where my problem lies.
aaExtractCommonList tugal.xls
ABCD
1# Of Common Items4
2List1List20Common List
3aa1a
4bb2b
5cc3c
6dw4d
7ex  
8fd
9gz
10
Sheet1


Formulas...

C2 must house a 0.

C3, copied down:

=IF((A3<>"")*ISNA(MATCH(A3,$A$2:A2,0))*ISNUMBER(MATCH(A3,B:B,0)),LOOKUP(9.99999999999999E+307,$C$2:C2)+1,"")

D1:

=LOOKUP(9.99999999999999E+307,C:C)

=IF(ROW()-ROW($D$3)+1<=$D$1,LOOKUP(ROW()-ROW($D$3)+1,C:C,A:A),"")

Note that the foregoing shares the same core as my contrib in the link rs2k quoted.
 
Upvote 0

Forum statistics

Threads
1,215,695
Messages
6,126,261
Members
449,307
Latest member
Andile

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