Make a new sheet, named by cell value

blaksnm

Well-known Member
Joined
Dec 15, 2009
Messages
554
Office Version
  1. 365
Platform
  1. Windows
Hey guys :)
Based on an active celle I want to create a new sheet in my workbook by copy a "template sheet and rename this copy as indentical to the active cell value.
The active cell value is unique in my list.

Can anyone guide me on this one?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try this one.

Code:
Sub CreateSheet()

    Dim shTemplate As Worksheet, cell As Range
    
    Set cell = ActiveCell
    Set shTemplate = Sheets("Template")
    
    shTemplate.Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Name = cell.Value

End Sub
 
Upvote 0
:)
Magnificant! Super-thank you!
How will I overwrite if the sheetsname alleready exist?
 
Upvote 0
Code:
Sub CreateSheet()

    Dim shTemplate As Worksheet, cell As Range

    Application.DisplayAlerts = False    

    Set cell = ActiveCell
    
    If SheetExists(cell.Value) Then Sheets(cell.Value).Delete
        
    Set shTemplate = Sheets("Template")
    shTemplate.Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Name = cell.Value
    
    Application.DisplayAlerts = True
        
End Sub

Function SheetExists(SheetName As String) As Boolean
    Dim sh As Worksheet
    On Error Resume Next
    Set sh = Worksheets(sh)
    If Not sh Is Nothing Then SheetExists = True
End Function
 
Last edited:
Upvote 0
There's little change in code - see my last code.
 
Upvote 0
Im sorry - the "delete" command did not work:

The makro creates the Sheet "Tempate(2)" all right, but crashes after that messaging that the new name allready exists. :)
 
Upvote 0
You messed up something. If sheet exists, it deletes it and then creates new sheet.
 
Upvote 0
Apearntly :)
It seems that the command:
If SheetExists(cell.Value) Then Sheets(cell.Value).Delete
not really find the sheet to delete if it exists allready, and crashes the macro.
 
Upvote 0

Forum statistics

Threads
1,224,541
Messages
6,179,418
Members
452,912
Latest member
alicemil

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