Create and name new worksheet

georgecomstock

New Member
Joined
May 27, 2011
Messages
18
Hi I wonder if anyone could help? I want to create a new worksheet with the name being derived from the value in a cell. So, looking through the range say a2:a10 if the string value contained in any of those cells does not match the name of an existing sheet in the workbook to create a sheet using the string value found in the cell.

Hope I've made myself clear and hope that you can help. Many thanks.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Code:
Sub CreateSheets()

    Dim cell As Range, sh As Worksheet
    
    For Each cell In Range("A2:A10")
        If Not IsEmpty(cell) Then
            If Not SheetExists(cell.Value) Then
                Set sh = Worksheets.Add
                sh.Name = cell
            End If
        End If
    Next

End Sub

Function SheetExists(SheetName As String) As Boolean
    Dim sh As Worksheet
    On Error Resume Next
    Set sh = Worksheets(SheetName)
    If Not sh Is Nothing Then SheetExists = True
End Function
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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