Copy Worksheet Throws Runtime Error 424 Object Required

NorthbyNorthwest

Board Regular
Joined
Oct 27, 2013
Messages
147
Office Version
  1. 365
Hoping someone can help me with error problem. I am trying to copy a worksheet several timeswithin a workbook and assign new names to sheets. However, the procedure throws runtime error424 "object required" on line which reads: Sheets(3).CopyAfter:=Sheets(Sheets.Count). It thengoes on to copy and name sheets; however, the procedure ends. What can I do to prevent the error? I have subsequent code I’d like the procedureto run.
VBA Code:
With ThisWorkbook.Sheets(3)
.Visible = xlSheetVisible
.Activate
.Range("A7").Select
End With

    Sheets(3).CopyAfter:=Sheets(Sheets.Count)
Set ws =ActiveSheet
 ws.Name ="Alpha"

Sheets(3).CopyAfter:=Sheets(Sheets.Count)
Set ws =ActiveSheet
ws.Name ="Bravo"

Sheets(3).CopyAfter:=Sheets(Sheets.Count)
Set ws =ActiveSheet
ws.Name ="Charlie"

Sheets(3).CopyAfter:=Sheets(Sheets.Count)
Set ws =ActiveSheet
ws.Name ="Delta"
 
Last edited by a moderator:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Thanks, Smitty for quick reply. Unfortunately, I do have space between two words. It's my first time posting code between code tags. I tried to remove lines and sort of mangled the code. I guess I need more practice. See reposted code.

VBA Code:
With ThisWorkbook.Sheets(3)
.Visible =xlSheetVisible
.Activate
.Range("A7").Select
End With

Sheets(3).CopyAfter:=Sheets(Sheets.Count)
Set ws =ActiveSheet
ws.Name ="Alpha"

Sheets(3).CopyAfter:=Sheets(Sheets.Count)
Set ws =ActiveSheet
ws.Name ="Bravo"

Sheets(3).CopyAfter:=Sheets(Sheets.Count)
Set ws =ActiveSheet
ws.Name ="Charlie"

Sheets(3).CopyAfter:=Sheets(Sheets.Count)
Set ws =ActiveSheet
ws.Name ="Delta"


Any additional help you could give me would be greatly appreciated.
 
Last edited by a moderator:
Upvote 0
This works fine for me:

VBA Code:
Sub foo()
    Dim ws As Worksheet
   
    With ThisWorkbook.Sheets(3)
        .Visible = xlSheetVisible
        .Activate
       .Range("A7").Select
    End With

    Sheets(3).Copy After:=Sheets(Sheets.Count)
    Set ws = ActiveSheet
    ws.Name = "Alpha"

    Sheets(3).Copy After:=Sheets(Sheets.Count)
    Set ws = ActiveSheet
    ws.Name = "Bravo"

    Sheets(3).Copy After:=Sheets(Sheets.Count)
    Set ws = ActiveSheet
    ws.Name = "Charlie"

    Sheets(3).Copy After:=Sheets(Sheets.Count)
    Set ws = ActiveSheet
    ws.Name = "Delta"
End Sub
 
Last edited by a moderator:
Upvote 0
Solution
Thanks, Smitty. I'm going to follow your lead and break up procedure in smaller parts (three to be exact). Copying the sheets was part I. Copying data rows for Alpha, Bravo, Charlie, and Delta from a Summary Sheet to the individual sheets I created was part II. (Alpha, Bravo, Charlie, and Delta appear in one the Summary sheet columns). And part III was moving the Alpha, Bravo, Charlie, and Delta worksheets to their own individual workbooks. Maybe I'm trying to do too much in one procedure given my skill level right now.
 
Upvote 0
You might want to post the code in its entirety in the future so we can see what you're trying to do. I only got to test what you posted...;)
 
Upvote 0

Forum statistics

Threads
1,203,665
Messages
6,056,638
Members
444,879
Latest member
suzndush

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