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
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
10,238
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?
 

Some videos you may like

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

mrsect

New Member
Joined
Jan 11, 2021
Messages
13
Office Version
  1. 365
Platform
  1. Windows
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
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
10,238
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
 

mrsect

New Member
Joined
Jan 11, 2021
Messages
13
Office Version
  1. 365
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,127,328
Messages
5,624,036
Members
416,007
Latest member
csf

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
Top