Insert data from different sheets into one

richard1234567891011

Board Regular
Joined
Feb 21, 2018
Messages
91
Hello Guys,

I have two similar tables in different sheets and I want them both in one sheet.

What do you think is the best way?

A macro? A formula?
And in case, what is the macro or formula?

This is the example:
Sheet: Aste

1574198711354.png


Sheet: Datio

1574198720918.png


Expected result:
Sheet: Aste+Datio

1574198736858.png


Thank you guys,
Kind regards.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try this macro

VBA Code:
Sub Insert_data()
  Dim sh1 As Worksheet, sh2 As Worksheet, lr1 As Long, lr2 As Long, wmax As Long
  Set sh1 = Sheets("Aste")
  Set sh2 = Sheets("Datio")
  lr1 = sh1.Range("C" & Rows.Count).End(xlUp).Row
  lr2 = sh2.Range("C" & Rows.Count).End(xlUp).Row - 1
  wmax = sh1.Range("C" & lr1).Value + 1
  sh1.Range("A" & lr1 + 1).Resize(lr2, 9).Value = sh2.Range("A2").Resize(lr2, 9).Value
  sh1.Range("C" & lr1 + 1).Resize(lr2).Value = wmax
End Sub
 
Upvote 0
Thank you very much.

But The macro stops to work here: wmax = sh1.Range("C" & lr1).Value + 1
If this part is related to asset column and the asset counting, I already have a formula in C5 (table expected results), because data starts in C5 in both sheets.

=IF(E5="";"";IF(A5=1;1;IF(E5=E4;SUM(C4);SUM(C4)+1)))

Therefore I can also paste staring from the column D.

Thank you.
 
Upvote 0
That was not in your original requirement.
What the macro does is continue with the numbering, just as you put it in your examples.
Delete your formulas and try the macro again.
 
Upvote 0
That was not in your original requirement.
What the macro does is continue with the numbering, just as you put it in your examples.
Delete your formulas and try the macro again.

Thank you very much, but is it possibile to change it a little?

It is perfect, but I would like this 2 changes:

Cell reference no A1 but A4 as first, so, in A5 the first 1
The merge of the two tables not in the same table, but in another one, called for example master or something similar

I don't have experience in macros so I don't know how to make this 2 changes.

Thank you very much, you are helping me a lot.
 
Upvote 0
I'm sorry but I didn't understand any of the 2 changes.
You can give several examples of what you have and what you expect from the result.

Upload an excel range:
XL2BB - Excel Range to BBCode
 
Upvote 0
I'm sorry but I didn't understand any of the 2 changes.
You can give several examples of what you have and what you expect from the result.

Upload an excel range:
XL2BB - Excel Range to BBCode


Cell reference no A1 but A4 as first, so, in A5 the first 1
The merge of the two tables not in the same table, but in another one, called for example master or something similar

In This way, as the screen.


Screenshot 2019-11-20 at 19.09.28.png
 
Upvote 0
I updated the macro so you could keep your formula in the "Aste" sheet column C sheet

VBA Code:
Sub Insert_data()
  Dim sh1 As Worksheet, sh2 As Worksheet, sh3 As Worksheet
  Dim lr1 As Long, lr2 As Long, lr3 As Long, wMax As Long
  Set sh1 = Sheets("Aste")
  Set sh2 = Sheets("Datio")
  Set sh3 = Sheets("Master")
  sh3.Rows("5:" & Rows.Count).ClearContents
  lr1 = 2
  Do While sh1.Range("C" & lr1).Value <> ""
    lr1 = lr1 + 1
  Loop
  lr1 = lr1 - 1
  lr2 = 2
  Do While sh2.Range("C" & lr2).Value <> ""
    lr2 = lr2 + 1
  Loop
  lr2 = lr2 - 2
  sh3.Range("A5").Resize(lr1, 9).Value = sh1.Range("A2").Resize(lr1, 9).Value
  lr3 = sh3.Range("C" & Rows.Count).End(xlUp).Row
  wMax = sh3.Range("C" & lr3).Value + 1
  sh3.Range("A" & lr3 + 1).Resize(lr2, 9).Value = sh2.Range("A2").Resize(lr2, 9).Value
  sh3.Range("C" & lr3 + 1).Resize(lr2).Value = wMax
End Sub
 
Upvote 0
I updated the macro so you could keep your formula in the "Aste" sheet column C sheet

VBA Code:
Sub Insert_data()
  Dim sh1 As Worksheet, sh2 As Worksheet, sh3 As Worksheet
  Dim lr1 As Long, lr2 As Long, lr3 As Long, wMax As Long
  Set sh1 = Sheets("Aste")
  Set sh2 = Sheets("Datio")
  Set sh3 = Sheets("Master")
  sh3.Rows("5:" & Rows.Count).ClearContents
  lr1 = 2
  Do While sh1.Range("C" & lr1).Value <> ""
    lr1 = lr1 + 1
  Loop
  lr1 = lr1 - 1
  lr2 = 2
  Do While sh2.Range("C" & lr2).Value <> ""
    lr2 = lr2 + 1
  Loop
  lr2 = lr2 - 2
  sh3.Range("A5").Resize(lr1, 9).Value = sh1.Range("A2").Resize(lr1, 9).Value
  lr3 = sh3.Range("C" & Rows.Count).End(xlUp).Row
  wMax = sh3.Range("C" & lr3).Value + 1
  sh3.Range("A" & lr3 + 1).Resize(lr2, 9).Value = sh2.Range("A2").Resize(lr2, 9).Value
  sh3.Range("C" & lr3 + 1).Resize(lr2).Value = wMax
End Sub


Thank you very much,

But there is something wrong, or I am doing something wrong.

Before It pasted two times the sheet Datio in the sample sheet in the screen,
Now is not working.

In the sample Sheet (without formula the one in the screen) I have this error: sh3.Range("A" & lr3 + 1).Resize(lr2, 9).Value = sh2.Range("A2").Resize(lr2, 9).Value

In the original sheet instead (with formula, the one were I have to really insert the macro, you didn't see it) I have this error: wMax = sh3.Range("C" & lr3).Value + 1

I am not forced to use a macro that allow me to have formulas in some cells, I only need a macro that built what is in the screen.

Thank you very much, you are very kind.
 
Upvote 0

Forum statistics

Threads
1,215,416
Messages
6,124,774
Members
449,187
Latest member
hermansoa

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