Subscript out of range error copying worksheet to new workbook

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,661
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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,226,112
Messages
6,189,039
Members
453,521
Latest member
Chris_Hed

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