Subscript out of range error copying worksheet to new workbook

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I need some help ...

Rich (BB code):
Fpath = "U:\PWS\Parks\Parks Operations\Sports\WATSOP19\STAFF\BackupData\"
fname = "staff_schedule_BU (" & Format(Now, "dd-mm-yy hh,mm,ss") & ").xlsm"
Set newbook = Workbooks.Add
wb_pstaff.Worksheets("STAFF_SCHEDULE").Copy after:=newbook.Worksheets("Sheet1")
If Dir(Fpath & fname) <> "" Then
    MsgBox "File " & Fpath & fname & " already exists.", vbExclamation, "FILE ERROR"
Else
    newbook.SaveAs filename:=Fpath & fname
    Set wb_staffschedulebu = Workbooks(fname)
    MsgBox "Backup : " & fname & " secured.", vbInformation, "SUCCESS"
End If
wb_staffschedulebu.Close

I am receiving a "Subscript out of range" error with the line in red.

Worksheet "STAFF_SCHEDULE" is found in workbook alias wb_pstaff (which is recognized properly) and I wish to copy it to a newly created workbook (newbook) after "Sheet1"

Thoughts?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I can't test......but I think you need

Code:
Workbooks.Add
ActiveWorkbook.SaveAs Filename:=Aname & ".xlsm"
Set newbook=activeworkbook
 
Upvote 0
Thank you Michael, I'm not sure if your suggestion would be a solution. I'm not having any problem creating or saving the new workbook, just copying a worksheet from one book to the other.

Much appreciate the effort!
 
Upvote 0
It must be getting late ... such a foolish error.
Its all good friends. Helps if I use the correct workbook.
 
Upvote 0
:laugh::laugh:....doesn't have to be late for me to make those !!!
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

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