Code to copy range from multiple worksheets into a master worksheet

dbuzbee

New Member
Joined
Nov 2, 2011
Messages
2
I am working on a workload tracking workbook for summarizing employee hours on key projects. The workbook contains multiple worksheets for reporting as well as individual employee worksheets for tracking. Each employee worksheet has an identical structure but the number of worksheets will vary as employees are added or leave the department. For each employee worksheet, I want to copy the same range (A9:R100) to one master worksheet (Summary) which will then be used for PivotTables and other reports.

What would be the best way to copy from the first employee worksheet (not the first one in the workbook), paste the range into Summary, and then move to the next worksheet and repeat until the last employee worksheet? The employee worksheets are currently between the StartHere and EndHere worksheets.

I'm trying a Do Until Loop but I get an "Object variable or With block variable not set" error on the line "ws.Range...."

Perhaps this should be a For-Next Loop or handled in some other way?

Sub Import()
'
Dim wsDest As Range
Dim ws As Worksheet

' Go to starting sheet to import
Sheets("StartHere").Select
Worksheets(ActiveSheet.Index + 1).Select

'Add Employee Details
Do Until ActiveSheet.Name = "EndHere"
With Sheets("Summary")
Set wsDest = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
End With
'Copy the range and paste into next cell in Summary
ws.Range("A9:R100").Copy Destination:=wsDest

Worksheets(ActiveSheet.Index + 1).Select

Loop
End Sub

Thanks in advance for your time
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Code:
Sub Import()
    '
    Dim i As Long
    
    'Add Employee Details
    With Sheets("Summary")
        For i = Sheets("StartHere").Index + 1 To Sheets("EndHere").Index - 1
            Sheets(i).Range("A9:R100").Copy Destination:=.Cells(.Rows.Count, "A").End(xlUp).Offset(1)
        Next i
    End With
End Sub
 
Upvote 0
Thank you for the quick response-looks good! Unfortunately, nothing happens when I run this code. When I step into it, the macro doesn't run past the Sub name. Curious
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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