Copy and Re-Name Worksheet using a cell value.

Pacman52

Active Member
Joined
Jan 29, 2009
Messages
401
Office Version
  1. 365
Platform
  1. Windows
Hi all

I'm having a few problems working put how to copy a Worksheet (WS) AND then re-name it using the value of a cell from a different sheet but in the same workbook (WB).

The WB is being used to enable the end user to click a button on the Menu WS that will show a specific type of Userform (dependant on what type of template they need to fill in) asking them to enter a relevant date.
Once they click OK the date is written to another Worksheet called 'Dates' into cell C3 then the relevant template WS needs to be copied and then renamed using the value in dates C3.

I have found and adjusted the following sub on this forum but it keeps erroring out with 'subscript out of range' and I really don't have a clue why

Could someone please help me to resolve this one.

Many thanks

Paul

VBA Code:
Sub NewTemplate()

Dim WSCount As Long
WSCount = Worksheets.Count

        ActiveWorkbook.Sheets("Template").Copy _
           After:=ActiveWorkbook.Sheets(WSCount)
            Sheets("Dates").Name = Sheets("Dates").Range("C3").Value & WSCount + 1

End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
See if this works :

VBA Code:
Option Explicit

Sub NewTemplate()

Dim WSCount As Long
WSCount = Worksheets.Count

        ActiveWorkbook.Sheets("Template").Copy _
           After:=ActiveWorkbook.Sheets(WSCount)
            ActiveSheet.Name = Sheets("Template").Range("C3").Value & WSCount + 1
            

End Sub
 
Upvote 0
Solution
Thanks so much for the reply, I've just tried that and it does now copy the template worksheet although I had to change the last line of the code to

VBA Code:
  ActiveSheet.Name = Sheets("Dates").Range("C3").Value

This was to reference the worksheet 'Dates' and remove the WSCount at the end of the new name.

Thank you again for the help though.

Paul
 
Upvote 0

Forum statistics

Threads
1,223,578
Messages
6,173,167
Members
452,504
Latest member
frankkeith2233

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