Comparing two coloumns in two worksheets and inserting it into a third one

lazycoder89

New Member
Joined
May 22, 2011
Messages
4
Hi,

I'm having problem in doing the following.
Suppose I have two excel files book1 and book2. Both have two coloumns ID and flag.
I need a macro that can read data from the 'ID' column of the excel(book1) where the value of 'flag' in column is "Y" from one sheet , compare it with the 'ID' of the second excel (book2) and only copy the data only where the IDs matches, to another sheet.

Also I need to know how can it be done in case it is only for two sheets instead of two different excel.

Thanks
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
it doesnt matter if the ranges are in same workbook or different

if the ranges are in same workbook refer to the sheets i.e.

thisworkbook.sheets( index_no / "sheet_name").range("A:A")

e.g.
Code:
thisworkbook.sheets("Sheet1").range("A:A")
and
thisworkbook.sheets("Sheet2").range("A:A")
If they are in different workbooks give workbook name as well. Make sure both the workbooks are open.
Code:
workbook("xyz.xls").sheets("name"/index_no).range("A:A")
and 
workbook("pqr.xls").sheets("name"/index_no).range("A:A")
...
Hope this hepls.....
 
Upvote 0
Say I have two workbooks book1.xls and bok2.xls

Both have two coloumns "id" and "flag". In book1 suppose there are 4 id rangin from 1 to 4 and the flags are Y,N,Y,Y respectively.
In the book 2 there are 4 id's ranging from 1 to 4 with flags Y,Y,N,Y respectively.

Now I want a macro that will open these two workbooks and go through the data and find the field that has same flag and copy those in a new excel file.
Like in this case the id 1 an 4 with their flags should get copied.
Hope I have made myself clear
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,908
Members
452,949
Latest member
beartooth91

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