Compile error: Invalid use of property

onlyonekj

New Member
Joined
Jun 27, 2019
Messages
18
Good Afternoon,

I am trying to copy a worksheet multiple times and rename them using a MasterList. The VBA code I've used in the past before worked but now I am receiving "Compile error: Invalid use of property". Below is the code I am using. Requesting assistance to fix this error. Thanks.

VBA Code:
Sub MakeSheets()
Dim sh1 As Worksheet, sh2 As Worksheet, c As Range
Set sh1 = Sheets("250")
Set sh2 = Sheets("MasterList")
For Each c In sh2.Range("A251:A300")
sh1.Copy After: Sheets (Sheet.Count)
ActiveSheet.Name = c.Value
Next
End Sub
 

Attachments

  • Compile Error.jpg
    Compile Error.jpg
    102.4 KB · Views: 11

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
You need After:= not just After:
 
Upvote 0
Solution
You need After:= not just After:
Thank you for responding. I tried that and now I am getting "Run-time error '424': Object required" in the portion with red font.

VBA Code:
Sub MakeSheets()
Dim sh1 As Worksheet, sh2 As Worksheet, c As Range
Set sh1 = Sheets("250")
Set sh2 = Sheets("MasterList")
    For Each c In sh2.Range("A251:A300")
       [COLOR=rgb(184, 49, 47)] sh1.Copy After:=Sheets(Sheet.Count)[/COLOR]
        ActiveSheet.Name = c.Value
    Next
End Sub
 

Attachments

  • Run-time Error '424'.jpg
    Run-time Error '424'.jpg
    90.1 KB · Views: 5
Upvote 0
Thank you for responding. I tried that and now I am getting "Run-time error '424': Object required" in the portion with red font.

VBA Code:
Sub MakeSheets()
Dim sh1 As Worksheet, sh2 As Worksheet, c As Range
Set sh1 = Sheets("250")
Set sh2 = Sheets("MasterList")
    For Each c In sh2.Range("A251:A300")
       [COLOR=rgb(184, 49, 47)] sh1.Copy After:=Sheets(Sheet.Count)[/COLOR]
        ActiveSheet.Name = c.Value
    Next
End Sub
RoryA, I also made the other change you recommended sh1.Copy After:=Sheets(Sheet.Count) to sh1.Copy After:=Sheet(Sheet.Count) but still get the Run-time error

VBA Code:
Sub MakeSheets()
Dim sh1 As Worksheet, sh2 As Worksheet, c As Range
Set sh1 = Sheets("250")
Set sh2 = Sheets("MasterList")
    For Each c In sh2.Range("A251:A300")
        sh1.Copy After:=Sheet(Sheet.Count)
        ActiveSheet.Name = c.Value
    Next
End Sub
 
Upvote 0
RoryA, I also made the other change you recommended sh1.Copy After:=Sheets(Sheet.Count) to sh1.Copy After:=Sheet(Sheet.Count) but still get the Run-time error

VBA Code:
Sub MakeSheets()
Dim sh1 As Worksheet, sh2 As Worksheet, c As Range
Set sh1 = Sheets("250")
Set sh2 = Sheets("MasterList")
    For Each c In sh2.Range("A251:A300")
        sh1.Copy After:=Sheet(Sheet.Count)
        ActiveSheet.Name = c.Value
    Next
End Sub
RoryA, I saw where I deleted the wrong. I have fixed it and the formula works now.
 
Upvote 0
@RoryA and @bstory84
I just want to say thank you for your help. Your suggestions worked perfectly. I also wanted to post the correct coding below and check this reply as solved in case it can be of use for someone else.

VBA Code:
Sub MakeSheets()
Dim sh1 As Worksheet, sh2 As Worksheet, c As Range
Set sh1 = Sheets("250")
Set sh2 = Sheets("MasterList")
For Each c In sh2.Range("A251:A300")
sh1.CopyAfter:=Sheets(Sheets.Count)
ActiveSheet.Name = c.Value
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,937
Members
449,196
Latest member
Maxkapoor

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