How to copy last row of data in all worksheets and paste it into one worksheet

overhead_press

New Member
Joined
Feb 7, 2022
Messages
1
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
Currently I have a lot of sheets in my Excel file but I am interested in getting the last row of data in sheets that start with "6" as their names as the other sheets are not relevant. In the sheets that start with 6 are all in the same format but have different number of rows, I am interested in extracting the last row in all those sheets (columns D:J) and placing it into a "master sheet". Since I am quite new to VBA, how would I go about doing that? Thanks in advance!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
So, if we are only going to copy the range D:J
When we put this data in a sheet named "Master"
I assume you want this data copied into the Master sheet stating in column A or is this not the case.
And you said Master sheet. I assume that means the sheet is name "Master"
 
Upvote 0
If the answers to my previous questions are true, then try this:
Run this script from the sheet named Master
VBA Code:
Sub Get_Left_Sheet_Name()
'Modified  2/7/2022  8:53:33 PM  EST
Application.ScreenUpdating = False
Dim i As Long
Dim lastrow As Long
Dim lastrowa As Long

For i = 1 To Sheets.Count

    If Left(Sheets(i).Name, 1) = "6" Then
        lastrowa = Sheets("Master").Cells(Rows.Count, "A").End(xlUp).Row + 1
        lastrow = Sheets(i).Cells(Rows.Count, "D").End(xlUp).Row
        Sheets(i).Cells(lastrow, "D").Resize(, 7).Copy Sheets("Master").Cells(lastrowa, 1)
    End If
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,568
Messages
6,120,272
Members
448,953
Latest member
Dutchie_1

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