Subscript out of range - coping specific sheets to new workbook

mssbass

Active Member
Joined
Nov 14, 2002
Messages
253
Platform
  1. Windows
This was running but all the sudden, I'm getting a subscript out of range error at this last line?

Dim wbO As Workbook, wbN As Workbook

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False

Set wbO = ActiveWorkbook
Set wbN = Workbooks.Add

wbO.Sheets("Exceptions").Copy wbN.Sheets(1)
 
I renamed the Exceptions worksheet to test and tried re-running as wbO.Sheets("test").Copy WbN.Sheets(1) and now getting Automation error Invalid forward reference, or reference to uncompiled type?
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
In that case please post your entire code.
 
Upvote 0
VBA Code:
Sub SaveVC()
Dim wbO As Workbook, wbN As Workbook

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False

Set wbO = ThisWorkbook
Set wbN = Workbooks.Add

wbO.Sheets("test").Copy wbN.Sheets(1)
wbO.Sheets("UM").Copy wbN.Sheets(2)
wbO.Sheets("Sleep").Copy wbN.Sheets(3)

wbN.Sheets("Sheet1").Delete

wbN.Sheets("Exceptions").Range("A1:H1").Copy
wbN.Sheets("Exceptions").Range("A1:H1").PasteSpecial Paste:=xlPasteValues
wbN.Sheets("UM").Range("A1:E1").Copy
wbN.Sheets("UM").Range("A1:E1").PasteSpecial Paste:=xlPasteValues
wbN.Sheets("Sleep").Range("A1:E1").Copy
wbN.Sheets("Sleep").Range("A1:E1").PasteSpecial Paste:=xlPasteValues

wbN.Sheets("Exceptions").Activate

txtdate = Format(Now - 1, "mm") & "." & Format(Now - 1, "dd") & "." & Format(Now - 1, "yy")
File1 = "\\abc.com\Daily Closed Auto " & txtdate & ".xlsx"

If Dir(File1) <> "" Then
Kill File1
Else
End If

wbN.SaveAs Filename:="\\abc.com\Daily Closed Auto " & txtdate & ".xlsx"

wbN.Close

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True

End Sub
 
Upvote 0
That works fine for me.
Do you get any error messages.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,605
Members
449,089
Latest member
Motoracer88

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