Copy data from all sheets and specific range into master workbook

mrsect

New Member
Joined
Jan 11, 2021
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a workbook that contains multiple sheets, each sheet is named differently but each sheet contains the same type of data looking to select all the sheets and copy data from all sheets range a-h and paste into master workbook
 
Are the Master workbook and the "7.27.2020.xlsx" workbook saved in the same folder? If different, what is the full path to the folder where "7.27.2020.xlsx" is saved? In your original post you said that you want to copy the range A:H from each worksheet. Is this correct? Is there a reason why columns B:F are hidden in all the sheets?
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Are the Master workbook and the "7.27.2020.xlsx" workbook saved in the same folder? If different, what is the full path to the folder where "7.27.2020.xlsx" is saved? In your original post you said that you want to copy the range A:H from each worksheet. Is this correct? Is there a reason why columns B:F are hidden in all the sheets?
they are in the same folder - \\users\desktop\Master Payroll and the range now is W-AP
 
Upvote 0
Try this macro. Please note that it also copies the hidden columns.
VBA Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim LastRow As Long, lRow As Long, srcWB As Workbook, desWB As Workbook, desWS As Worksheet, ws As Worksheet
    Set desWB = ThisWorkbook
    Set desWS = desWB.Sheets("Master")
    Set srcWB = Workbooks.Open(desWB.Path & "\7.27.2020.xlsx")
    For Each ws In Sheets
        If ws.Name <> "TEMPLATE" Then
            LastRow = ws.Columns(23).Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            lRow = desWS.Range("A" & desWS.Rows.Count).End(xlUp).Row + 1
            ws.Range("W1:AP" & LastRow).Copy
            desWS.Range("A" & lRow).PasteSpecial xlPasteValues
        End If
    Next ws
    desWS.Columns.AutoFit
    desWS.Rows(1).Delete
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try this macro. Please note that it also copies the hidden columns.
VBA Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim LastRow As Long, lRow As Long, srcWB As Workbook, desWB As Workbook, desWS As Worksheet, ws As Worksheet
    Set desWB = ThisWorkbook
    Set desWS = desWB.Sheets("Master")
    Set srcWB = Workbooks.Open(desWB.Path & "\7.27.2020.xlsx")
    For Each ws In Sheets
        If ws.Name <> "TEMPLATE" Then
            LastRow = ws.Columns(23).Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            lRow = desWS.Range("A" & desWS.Rows.Count).End(xlUp).Row + 1
            ws.Range("W1:AP" & LastRow).Copy
            desWS.Range("A" & lRow).PasteSpecial xlPasteValues
        End If
    Next ws
    desWS.Columns.AutoFit
    desWS.Rows(1).Delete
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
Thank you!!!!!! I had to change the code a little to make it work but it works
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,238
Members
448,555
Latest member
RobertJones1986

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