VBA code to match id and Date from sheet1 with Sheet 2 and copy matching rows and unmatched with blank

motherindia

Board Regular
Joined
Oct 15, 2015
Messages
218
Hi Friends,

I Have two Sheets.

Sheet 1 Contains following data;




[TABLE="width: 599"]
<tbody>[TR]
[TD]ID No
[/TD]
[TD]Country
[/TD]
[TD]Sdate
[/TD]
[TD]E Date
[/TD]
[TD]Type
[/TD]
[TD]Nature
[/TD]
[TD]Text Contetns
[/TD]
[TD] Days
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]Finland
[/TD]
[TD]26-Jun-15
[/TD]
[TD]1-Jul-15
[/TD]
[TD]LD
[/TD]
[TD]Paid
[/TD]
[TD]ALL
[/TD]
[TD]6
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]Ireland
[/TD]
[TD]2-Jul-15
[/TD]
[TD]7-Jul-15
[/TD]
[TD]LD
[/TD]
[TD]Paid
[/TD]
[TD]ALL
[/TD]
[TD]6
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]Ireland
[/TD]
[TD]8-Jul-15
[/TD]
[TD]8-Jul-15
[/TD]
[TD]LD
[/TD]
[TD]Paid
[/TD]
[TD]ALL
[/TD]
[TD]0.5
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]Ireland
[/TD]
[TD]8-Jul-15
[/TD]
[TD]8-Jul-15
[/TD]
[TD]PD
[/TD]
[TD]unpaid
[/TD]
[TD]ALL
[/TD]
[TD]0.5
[/TD]
[/TR]
</tbody>[/TABLE]



[TABLE="width: 597"]
<tbody>[TR]
[TD]Sheet2 Contains
I want to math ID NO and Date of Shee2 with Sheet1 and copy the matching rows to Sheet3. If no matches found then it should be blank


[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
</tbody>[/TABLE]


ID NO Date
[TABLE="width: 592"]
<tbody>[TR]
[TD]1111111
[/TD]
[TD]26-Jun-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]27-Jun-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]28-Jun-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]29-Jun-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]30-Jun-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]01-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]02-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]03-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]04-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]05-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]06-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]07-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]08-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]10-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]11-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]12-Jul-15
[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Which date in Sheet 1 are you matching? Also, to be sure we understand, based upon your example, what should sheet 3 look like?
 
Upvote 0
Thanks for quick response sir.

Basically I need to check if ID match in both sheet, then I need to match Date in Sheet2 between start date and end date in Sheet1 . If Match found then it should be copied to Sheet 3. In case there is duplicate date in SHeet1 then it should be copied as it is. If Date in SHeet 1 is not in Sheet 2 against matching ID, then it has to copied to 3rd Sheet with ID and date of Sheet2.

After running macro the result should be as follows;


[TABLE="width: 609"]
<tbody>[TR]
[TD]Emp no[/TD]
[TD]Days[/TD]
[TD]Country[/TD]
[TD]Type[/TD]
[TD]Nature[/TD]
[TD]Text Contetns[/TD]
[TD]Days[/TD]
[/TR]
[TR]
[TD]1111111[/TD]
[TD]26-Jun-15[/TD]
[TD]Finland[/TD]
[TD]LD[/TD]
[TD]Paid[/TD]
[TD]ALL[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]1111111[/TD]
[TD]27-Jun-15[/TD]
[TD]Finland[/TD]
[TD]LD[/TD]
[TD]Paid[/TD]
[TD]ALL[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]1111111[/TD]
[TD]28-Jun-15[/TD]
[TD]Finland[/TD]
[TD]LD[/TD]
[TD]Paid[/TD]
[TD]ALL[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]1111111[/TD]
[TD]29-Jun-15[/TD]
[TD]Finland[/TD]
[TD]LD[/TD]
[TD]Paid[/TD]
[TD]ALL[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]1111111[/TD]
[TD]30-Jun-15[/TD]
[TD]Finland[/TD]
[TD]LD[/TD]
[TD]Paid[/TD]
[TD]ALL[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]1111111[/TD]
[TD]01-Jul-15[/TD]
[TD]Finland[/TD]
[TD]LD[/TD]
[TD]Paid[/TD]
[TD]ALL[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]1111111[/TD]
[TD]02-Jul-15[/TD]
[TD]Ireland[/TD]
[TD]LD[/TD]
[TD]Paid[/TD]
[TD]ALL[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]1111111[/TD]
[TD]03-Jul-15[/TD]
[TD]Ireland[/TD]
[TD]LD[/TD]
[TD]Paid[/TD]
[TD]ALL[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]1111111[/TD]
[TD]04-Jul-15[/TD]
[TD]Ireland[/TD]
[TD]LD[/TD]
[TD]Paid[/TD]
[TD]ALL[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]1111111[/TD]
[TD]05-Jul-15[/TD]
[TD]Ireland[/TD]
[TD]LD[/TD]
[TD]Paid[/TD]
[TD]ALL[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]1111111[/TD]
[TD]06-Jul-15[/TD]
[TD]Ireland[/TD]
[TD]LD[/TD]
[TD]Paid[/TD]
[TD]ALL[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]1111111[/TD]
[TD]07-Jul-15[/TD]
[TD]Ireland[/TD]
[TD]LD[/TD]
[TD]Paid[/TD]
[TD]ALL[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]1111111[/TD]
[TD]08-Jul-15[/TD]
[TD]inland[/TD]
[TD]LD[/TD]
[TD]Paid[/TD]
[TD]ALL[/TD]
[TD="align: right"]0.5[/TD]
[/TR]
[TR]
[TD]1111111[/TD]
[TD]08-Jul-15[/TD]
[TD]inland[/TD]
[TD]PD[/TD]
[TD]unpaid[/TD]
[TD]ALL[/TD]
[TD="align: right"]0.5[/TD]
[/TR]
[TR]
[TD]1111111[/TD]
[TD]10-Jul-15[/TD]
[TD]inland[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1111111[/TD]
[TD]11-Jul-15[/TD]
[TD]inland[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1111111[/TD]
[TD]12-Jul-15[/TD]
[TD]inland[/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD][/TD]
[/TR]
</tbody><colgroup><col><col><col><col><col><col><col></colgroup>[/TABLE]
 
Upvote 0
Hi Friends,

I Have two Sheets.

Sheet 1 Contains following data;





[TABLE="width: 599"]
<tbody>[TR]
[TD]ID No
[/TD]
[TD]Country
[/TD]
[TD]Sdate
[/TD]
[TD]E Date
[/TD]
[TD]Type
[/TD]
[TD]Nature
[/TD]
[TD]Text Contetns
[/TD]
[TD]Days
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]Finland
[/TD]
[TD]26-Jun-15
[/TD]
[TD]1-Jul-15
[/TD]
[TD]LD
[/TD]
[TD]Paid
[/TD]
[TD]ALL
[/TD]
[TD]6
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]Ireland
[/TD]
[TD]2-Jul-15
[/TD]
[TD]7-Jul-15
[/TD]
[TD]LD
[/TD]
[TD]Paid
[/TD]
[TD]ALL
[/TD]
[TD]6
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]Ireland
[/TD]
[TD]8-Jul-15
[/TD]
[TD]8-Jul-15
[/TD]
[TD]LD
[/TD]
[TD]Paid
[/TD]
[TD]ALL
[/TD]
[TD]0.5
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]Ireland
[/TD]
[TD]8-Jul-15
[/TD]
[TD]8-Jul-15
[/TD]
[TD]PD
[/TD]
[TD]unpaid
[/TD]
[TD]ALL
[/TD]
[TD]0.5
[/TD]
[/TR]
</tbody>[/TABLE]
Sheet2 Contains 2 columns

ID NO Date
[TABLE="width: 592"]
<tbody>[TR]
[TD]1111111
[/TD]
[TD]26-Jun-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]27-Jun-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]28-Jun-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]29-Jun-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]30-Jun-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]01-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]02-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]03-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]04-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]05-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]06-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]07-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]08-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]10-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]11-Jul-15
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]12-Jul-15
[/TD]
[/TR]
</tbody>[/TABLE]
Basically I need to check if ID match in both sheet, then I need to match Date in Sheet2 between start date and end date in Sheet1 . If Match found then it should be copied to Sheet 3. In case there is duplicate date in SHeet1 then it should be copied as it is. If Date in SHeet 1 is not in Sheet 2 against matching ID, then it has to copied to 3rd Sheet with ID and date of Sheet2.

After running macro the result should be as follows;



[TABLE="width: 609"]
<tbody>[TR]
[TD]Emp no
[/TD]
[TD]Days
[/TD]
[TD]Country
[/TD]
[TD]Type
[/TD]
[TD]Nature
[/TD]
[TD]Text Contetns
[/TD]
[TD]Days
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]26-Jun-15
[/TD]
[TD]Finland
[/TD]
[TD]LD
[/TD]
[TD]Paid
[/TD]
[TD]ALL
[/TD]
[TD]1
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]27-Jun-15
[/TD]
[TD]Finland
[/TD]
[TD]LD
[/TD]
[TD]Paid
[/TD]
[TD]ALL
[/TD]
[TD]1
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]28-Jun-15
[/TD]
[TD]Finland
[/TD]
[TD]LD
[/TD]
[TD]Paid
[/TD]
[TD]ALL
[/TD]
[TD]1
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]29-Jun-15
[/TD]
[TD]Finland
[/TD]
[TD]LD
[/TD]
[TD]Paid
[/TD]
[TD]ALL
[/TD]
[TD]1
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]30-Jun-15
[/TD]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[TD]unpaid
[/TD]
[TD]ALL
[/TD]
[TD]0.5
[/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]10-Jul-15
[/TD]
[TD]inland
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]11-Jul-15
[/TD]
[TD]inland
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1111111
[/TD]
[TD]12-Jul-15
[/TD]
[TD]inland
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Mother India
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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