Add a worksheet with the name of a selected cell (which changes)

Griffin29

New Member
Joined
Oct 18, 2013
Messages
16
Hi, I'm struggling to work this out despite me thinking it really cannot be hard (still very much a newbie).

I want to select a cell in an existing worksheet then run a macro that inserts a new sheet (at the end) and names it the contents of the active cell. An added bonus would be to Paste the same cell data into the new worksheet at A1. I've only got this far and clearly the rename doesn't work :-(

Dim newsheet
Set newsheet = Sheets.Add(After:=Sheets(Worksheets.Count), Count:=1, Type:=xlWorksheet)
newsheet.Name = ActiveCell.Value


Edit***** a really cheeky extra question - Is it possible to turn the selected cell into a hyperlink to the new sheet of the same name ? so if I select a cell with contents of "Dave", a new sheet called Dave will be made and the cell would become a link to it ?





Many thanks,
 
Last edited:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
VBA Code:
Sub Cheeky_Dave()
    With ActiveCell
        If .Value <> Empty Then
            If Not Evaluate("ISREF('" & .Value & "'!A1)") Then 'Test if worksheet name exists
                Worksheets.Add After:=Sheets(Sheets.Count)
                ActiveSheet.Name = .Value
                Range("A1").Value = .Value
                .Parent.Hyperlinks.Add Anchor:=.Cells(1), Address:="", SubAddress:="'" & .Value & "'!A1", TextToDisplay:=.Value
                .Parent.Select
            Else:
                MsgBox "A sheet named '" & .Value & "' already exists. ", vbExclamation, "Invalid Sheet Name"
            End If
        End If
    End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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