VBA copy range from multiple sheets into one, adding the sheet name

AriannaVV

New Member
Joined
Aug 6, 2017
Messages
34
Office Version
  1. 365
Platform
  1. Windows
Hi everyone!
I found in this forum (VBA - Copy and Paste Range From Multiple Sheets into Summary) the following code (changed somehow in order to transfer various ranges of cells from specific sheets in a new sheet called "summary"). Works great but when I run again the code to add data below previous copied range, selecting different sheets this time, it ovewrittes the first row and then continues nicely all other rows after the previous last row. Can anyone help to find out what goes wrong?
And another one question. Is it possible to mention the namesheet from where each result comes from? Thank you very much for your kind help.
VBA Code:
Sub Copy_Range_From_Sheets_De()

On Error GoTo M
 
Application.ScreenUpdating = False
 Dim i As Long
Dim ans As String
Dim Lastrow As Long
Dim Lastrowa As Long
Lastrow = Sheets("de.").Cells(Rows.Count, "A").End(xlUp).Row
Lastrowa = 3
For i = 2 To Lastrow
     ans = Sheets("de.").Cells(i, 1).Value
 With Sheets(ans)
 .Range("e93:o93").Copy
 Sheets("Summary").Cells(Lastrowa, 1).PasteSpecial xlPasteValues
  Lastrowa = Sheets("Summary").Cells(Rows.Count, "A").End(xlUp).Row + 1
 End With
 With Sheets(ans)

 .Range("e141:o141").Copy
  Sheets("Summary").Cells(Lastrowa, 1).PasteSpecial xlPasteValues
   Lastrowa = Sheets("Summary").Cells(Rows.Count, "A").End(xlUp).Row + 1
  End With
  Next
  Application.ScreenUpdating = True
 Exit Sub
M:
 MsgBox "You tried to use a sheet name that does not exist" & vbNewLine & "Or we had another problem"
 Application.ScreenUpdating = True
End Sub
 
In future please mark the post the contains the solution, not your post saying it works. Thanks
Hi. Thanks for the info, but I had already marked the post with the solution. I did that right after I replied the post above. Unless there is something else I need to do that I don't know, so pls advice. Thanks again everyone for your kind help.
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You marked your reply as the solution, which I changed to Mark858's
 
Upvote 0
You marked your reply as the solution, which I changed to Mark858's
ooo, sorry for this! Most of the times I mark the wrong reply and I get an automatic message to correct. This time it seems I missed it. Thanks for the notice. 🥰🥰
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,181
Members
452,615
Latest member
bogeys2birdies

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