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.
 
I am not understanding what you have on each sheet.
You are supposed to have this on each sheet.

Book1
ABCDEFGHI
1numcdaassetDatioctsubtipndgmq
2111/11/20191aste2ct2sub2tip2ndg2mq2
3212/11/20192aste3ct3sub3tip3ndg3mq3
4313/11/20193aste4ct4sub4tip4ndg4mq4
5414/11/20194aste5ct5sub5tip5ndg5mq5
6515/11/20195aste6ct6sub6tip6ndg6mq6
Aste


Book1
ABCDEFGHI
1numcdaassetastectsubtipndgmq
2111/11/20191aste2ct2sub2tip2ndg2mq2
3212/11/20191aste3ct3sub3tip3ndg3mq3
4313/11/20191aste4ct4sub4tip4ndg4mq4
5414/11/20191aste5ct5sub5tip5ndg5mq5
6515/11/20191aste6ct6sub6tip6ndg6mq6
7616/11/20191aste7ct7sub7tip7ndg7mq7
8717/11/20191aste8ct8sub8tip8ndg8mq8
9818/11/20191aste9ct9sub9tip9ndg9mq9
10919/11/20191aste10ct10sub10tip10ndg10mq10
111020/11/20191aste11ct11sub11tip11ndg11mq11
Datio



For that the macro works.

If you have something else on your sheets and the macro sends an error, then you must tell me what you have on each sheet, the macro's error message and the line where the code stops.
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I needed to update the macro to start in row 5 on each sheet.
Try this:

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 = 5
  Do While sh1.Range("C" & lr1).Value <> ""
    lr1 = lr1 + 1
  Loop
  lr1 = lr1 - 1
  lr2 = 5
  Do While sh2.Range("C" & lr2).Value <> ""
    lr2 = lr2 + 1
  Loop
  lr2 = lr2 - 5
  sh3.Range("A5").Resize(lr1 - 4, 9).Value = sh1.Range("A5").Resize(lr1 - 4, 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("A5").Resize(lr2, 9).Value
  sh3.Range("C" & lr3 + 1).Resize(lr2).Value = wMax
End Sub
 
Upvote 0
I'm glad to help you. Thanks for the feedback.


Dear DanteAmor,

Thank you again so much, I am using your macro and it is really really cool,

One last thing, The macro actually works and see until the column I. So It is able to read 9 Columns.

Is it possibile to increase the column to read?
So until column AS, so 45 columns.
Thank you again.
 
Upvote 0
Dear DanteAmor,
One last thing, The macro actually works and see until the column I. So It is able to read 9 Columns.
Is it possibile to increase the column to read?
So until column AS, so 45 columns.

Change the number 9 in the macro to the number 45, try and tell me.
 
Upvote 0
Again with pleasure. Thanks for the feedback

Dear DanteAmor,
I saw now an issue in your macro. It is indeed my fault because the macro is correct based on the data that I gave you.

The issue is that in the second file, it is not able to continue the counting.

1575042527456.png


1575042591370.png


If I add this line. Mantova. It is not able intact to increase the number.
The result is:

1575042645850.png

But it is wrong, because the 6 of Mantova should be 7.
It is not continuing the same counting as the first part.

Thank you again,
You are very kind.
 
Upvote 0
Try this

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, i 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
  sh3.Range("A" & lr3 + 1).Resize(lr2, 9).Value = sh2.Range("A2").Resize(lr2, 9).Value
  For i = lr3 + 1 To sh3.Range("C" & Rows.Count).End(xlUp).Row
    sh3.Range("C" & i).Value = sh3.Range("C" & i).Value + wMax
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,454
Members
449,083
Latest member
Ava19

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