Consolidating data with same headers from multiple worksheets into master worksheet

moonstex

New Member
Joined
Jun 18, 2015
Messages
11
Hi Guys,

PLease help me out. I need a VBA code or any other solution to produce the following.

Basically, I have two datasets where the same information is stored for different countries, and I need to merge them into one quite often.


Dataset 1 example


ABCD
1CountryTypeSub-typeAmount
2USAFruitApple3
3CanadaFruitOrange5
4SwedenVegetableTomato1
5NorwayfruitPear4
60000
70000
80000
90000
100000
110000

<tbody>
</tbody>

For every row where there is no data there is a 0

Dataset 2 example

ABCD
1CountryTypeSub-typeAmount
2AzerbaijanVegetableCucumber4
3IndiaFruitOrange1
4ThailandVegetableTomato1
5BangladeshFruitApple2
60000
70000
80000

<tbody>
</tbody>


Exactly same headers and same data but for different set of countries


Consolidated Dataset (this is what I'm trying to automate)

ABCD
1CountryTypeSub-TypeAmount
2USAFruitApple3
3CanadaFruitOrange5
4SwedenVegetableTomato1
5NorwayFruitPear4
6AzerbaijanVegetableCucumber4
7IndiaFruitOrange1
8ThailandVEgetableTomato1
9BangladeshFruitApple2

<tbody>
</tbody>

Basically, I want to copy paste all data from 2 datasets, right after each other without taking into account 0's. Zeros are basically blanks


Please help!

Thanks. S
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
This is just an example. In reality, both datasets have about 2000 rows and 150 columns and are updated daily. At the same times there are satellite tools that produce analysis based on the data in both. Before they were all in the same files, but due to multiple people working on the data, we decided to split based on countries. Now every time we need to run analysis from satelite tools, we have to copy paste. Would be amazing to make it more efficient somehow. Macro, or some kind of combines Pivot Tables, automatically refreshable sheet i don't know...
 
Upvote 0
CountryTypeSub-typeAmountCountryTypeSub-typeAmount
USAFruitApple3AzerbaijanVegetableCucumber4
CanadaFruitOrange5IndiaFruitOrange1
SwedenVegetableTomato1ThailandVegetableTomato1
NorwayfruitPear4BangladeshFruitApple2
00000000
this macro takes the valid rows from the 2 data sets
and merges them
rrow = 19
For j = 1 To 100
If Cells(j, 1) = 0 Then GoTo 100
rrow = rrow + 1
Cells(rrow, 1) = Cells(j, 1)
Cells(rrow, 2) = Cells(j, 2)
CountryTypeSub-typeAmount Cells(rrow, 3) = Cells(j, 3)
USAFruitApple3 Cells(rrow, 4) = Cells(j, 4)
CanadaFruitOrange5 Next j
SwedenVegetableTomato1100 For j = 2 To 100
NorwayfruitPear4 If Cells(j, 9) = 0 Then GoTo 200
AzerbaijanVegetableCucumber4 rrow = rrow + 1
IndiaFruitOrange1 Cells(rrow, 1) = Cells(j, 9)
ThailandVegetableTomato1 Cells(rrow, 2) = Cells(j, 10)
BangladeshFruitApple2 Cells(rrow, 3) = Cells(j, 11)
Cells(rrow, 4) = Cells(j, 12)
Next j
200 End Sub

<colgroup><col width="64" span="14" style="width:48pt"> </colgroup><tbody>
</tbody>
 
Upvote 0
Hi Guys,

PLease help me out. I need a VBA code or any other solution to produce the following.

Basically, I have two datasets where the same information is stored for different countries, and I need to merge them into one quite often.


Dataset 1 example


ABCD
1CountryTypeSub-typeAmount
2USAFruitApple3
3CanadaFruitOrange5
4SwedenVegetableTomato1
5NorwayfruitPear4
60000
70000
80000
90000
100000
110000

<tbody>
</tbody>

For every row where there is no data there is a 0

Dataset 2 example

ABCD
1CountryTypeSub-typeAmount
2AzerbaijanVegetableCucumber4
3IndiaFruitOrange1
4ThailandVegetableTomato1
5BangladeshFruitApple2
60000
70000
80000

<tbody>
</tbody>


Exactly same headers and same data but for different set of countries


Consolidated Dataset (this is what I'm trying to automate)

ABCD
1CountryTypeSub-TypeAmount
2USAFruitApple3
3CanadaFruitOrange5
4SwedenVegetableTomato1
5NorwayFruitPear4
6AzerbaijanVegetableCucumber4
7IndiaFruitOrange1
8ThailandVEgetableTomato1
9BangladeshFruitApple2

<tbody>
</tbody>

Basically, I want to copy paste all data from 2 datasets, right after each other without taking into account 0's. Zeros are basically blanks


Please help!

Thanks. S
Hi,
For example, Dataset 1 is in Sheet1, Dataset 2 is in Sheet2.
I make a Sheet3 with Form to Consolidate Data
ABCD
1CountryTypeSub-typeAmount

<tbody>
</tbody>
VBA code is:
Sub Consolidate_Data()
Dim Ws As Worksheet, I As Long, sR As Long, Rng As Range

For Each Ws In ThisWorkbook.Sheets
If Ws.Name <> "Sheet3" Then
With Ws
I = 2
Do While .Cells(I, 1) > 0
Set Rng = .Cells(I, 1).Resize(, 4)
With Sheet3
sR = .Range("A" & Rows.Count).End(xlUp).Row + 1
.Range("A" & sR).Resize(, 4) = Rng.Value
End With
I = I + 1
Loop
End With
End If
Next Ws
End Sub
 
Upvote 0
Hello,

I also would like to consolidate data. I have 7 companies (agencies) with 3 worksheets each (Worksheet A,B,C). Different agency related info on each worksheet. I would like to consolidate the data from all 7 companies and create one worksheet A, one worksheet B, and one Worksheet C. I have tried using multiple tables to create a pivot table and consolidating worksheets. The results have been less than stellar, but I have no experience with VBA codes. Can you help please?
 
Upvote 0
Hello,

I also would like to consolidate data. I have 7 companies (agencies) with 3 worksheets each (Worksheet A,B,C). Different agency related info on each worksheet. I would like to consolidate the data from all 7 companies and create one worksheet A, one worksheet B, and one Worksheet C. I have tried using multiple tables to create a pivot table and consolidating worksheets. The results have been less than stellar, but I have no experience with VBA codes. Can you help please?
I can solve your problem.
But I need your sample file to write VBA codes.
 
Upvote 0

Forum statistics

Threads
1,215,377
Messages
6,124,598
Members
449,174
Latest member
chandan4057

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