Merging Two Tables from Different Sheets based on Condition Using VBA

madhuchelliah

Board Regular
Joined
Nov 22, 2017
Messages
226
Office Version
  1. 2019
Platform
  1. Windows
Hello All, i have two tables in sheet1 and sheet2. I want to copy the row from sheet2 table and insert in sheet1 table. Please go through the example for better clarity.
VBA has to copy the rows with same value in sheet2 B column and stack the rows under the same value in sheet1 B column wherever the values are exists.
Consider the range as dynamic in both sheets. Thank you.

Book1
BCD
2BookSoldOnsale
3BookIn stockOut of Stock
4AAAAAAAAA
5BBBBBBBBB
6CCCCCCCCC
7DDDDDDDDD
8EEEEEEEEE
9BookSoldOnsale
10BookIn stockOut of Stock
11FFFFFFFFF
12GGGGGGGGG
13HHHHHHHHH
14BookSoldOnsale
15FFFFFFFFF
16GGGGGGGGG
17HHHHHHHHH
Sheet1


Book1
BCD
2BookAuthorPublisher
3BookFirst EditionReprint
4AAA00
5AAA111111
6BBB112112
7CCC113113
8DDD114114
9EEE115115
10FFF116116
11GGG117117
12HHH118118
Sheet2


Result:
Rows inserted from sheet2 are highlighted

Book1
BCD
2BookSoldOnsale
3BookIn stockOut of Stock
4BookAuthorPublisher
5BookFirst EditionReprint
6AAAAAAAAA
7AAA00
8AAA111111
9BBBBBBBBB
10BBB112112
11CCCCCCCCC
12CCC113113
13DDDDDDDDD
14DDD114114
15EEEEEEEEE
16EEE115115
17BookSoldOnsale
18BookIn stockOut of Stock
19BookAuthorPublisher
20BookFirst EditionReprint
21FFFFFFFFF
22FFF116116
23GGGGGGGGG
24GGG117117
25HHHHHHHHH
26HHH118118
27BookSoldOnsale
28BookAuthorPublisher
29BookFirst EditionReprint
30FFFFFFFFF
31FFF116116
32GGGGGGGGG
33GGG117117
34HHHHHHHHH
35HHH118118
Sheet1
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,022
Latest member
RobertV1609

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