Macro to add new worksheet & reference the new worksheet name in the worksheet

77winston

New Member
Joined
Sep 11, 2013
Messages
31
Office Version
  1. 2013
Platform
  1. Windows
Hi,
I hope someone could help me with a query I have.

I'm using a the below macro to create new worksheets to an workbook.

Sub CreateNewSheet()Dim sName As String
Sheets("Draw Data").Copy after:=ActiveSheet


sName = InputBox("Enter new sheet name")
On Error Resume Next
ActiveSheet.Name = sName
If Err <> 0 Then MsgBox "Name not valid"
Err.Clear
On Error GoTo 0
End Sub

This macro works fine, as an addition I want the sheet name that was entered to appear on cell B3 within the worksheet.
Could this be achieved?

Please advise.

Thanks.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
try:
Sub CreateNewSheet()Dim sName As String
Sheets("Draw Data").Copy after:=ActiveSheet


sName = InputBox("Enter new sheet name")
if sName = "" then 'Cancel was clicked
application.displayalerts=false
activesheet.delete
exit sub
end if
On Error Resume Next
ActiveSheet.Name = sName
If Err <> 0 Then
MsgBox "Name not valid"
application.displayalerts=false
activesheet.delete
exit sub
end if
range("B3").Value = sName
application.displayalerts=true
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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