Reputation: 197
I am trying to create a Macro that will Present an Input box once a button is clicked, simply saying "What would you like to call the new sheet?", then once the user has entered the name, Excel create a new sheet with that name.
However, I would like for the Data in the Original Sheet to be copied over to the new sheet that has been named by the user.
I have the Input box working, with this code:
Sub NewSheet()
Sheets.Add.Name = InputBox("What Would You Like to Call the New Sheet?")
End Sub
Upvotes: 1
Views: 1777
Reputation: 33672
Try the code below:
Sub NewSheet()
Dim origSht As Worksheet
Dim destSht As Worksheet
On Error GoTo eHandle
Set origSht = ActiveSheet
Sheets.Add.Name = InputBox("What Would You Like to Call the New Sheet?")
Set destSht = ActiveSheet
origSht.Cells.Copy Destination:=destSht.Cells
Exit Sub
eHandle:
MsgBox "You must name the new sheet"
set origSht = nothing
set destSht = nothing
End Sub
Upvotes: 7