rspalding

Active Member
Joined
Sep 4, 2009
Messages
282
Office Version
  1. 365
Platform
  1. Windows
I'm using the following code but get a runtime 424 error. Also, I would like to the sheet name in c17 to last cell

Private Sub CommandButton1_Click()
lastcell = ThisWorkbook.Worksheets("Master").Cells(Rows.Count, 1).End(xlUp).Row
For i = 17 To lastcell
With YhisWorkbook
newname = ThisWorkbook.Worksheets("Master").Cells(i, 1).Value
.Sheets.Add after:=.Sheets(.Sheets.Count)
ActiveSheet.Name = newname
End With
Next
ThisWorkbook.Worksheets("Master").Activate
ThisWorkbook.Worksheets("Master").Cells(1, 1).Select
End Sub

Thanks for the help...
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
One error here for starters....

Code:
With YhisWorkbook
 
Upvote 0
Michael M,

Thanks for catching the type-o. I looked multiple times and didn't see it. How can I tell the code to look at the corresponding cell in C column and tell it to copy the sheet named in "C"? So A will have the new sheet name but C will tell it which sheet to copy.

Thanks,
 
Upvote 0
If you put this declaration

Code:
Option Explicit

At the top of your code module ala:
Code:
Option Explicit

Private Sub CommandButton1_Click()
    lastcell = ThisWorkbook.Worksheets("Master").Cells(Rows.Count, 1).End(xlUp).Row
    For i = 17 To lastcell
        With YhisWorkbook
            newname = ThisWorkbook.Worksheets("Master").Cells(i, 1).Value
            .Sheets.Add after:=.Sheets(.Sheets.Count)
            ActiveSheet.Name = newname
        End With
    Next
    ThisWorkbook.Worksheets("Master").Activate
    ThisWorkbook.Worksheets("Master").Cells(1, 1).Select
End Sub

Then the compiler will help you catch errors like "YhisWorkbook" and by forcing you to declare all your variables, it will make it easier for us to help you when you post questions about your code.

BTW, I recommend you use code tags for clarity when posting code
attachment.php

attachment.php
 
Upvote 0

Forum statistics

Threads
1,215,475
Messages
6,125,028
Members
449,205
Latest member
Eggy66

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