Rename the sheet just added

  • Thread starter Thread starter Newbie
  • Start date Start date
N

Newbie

Hi,

I want to be able to programmatically insert a new worksheet and then rename
this newly added sheet to the contents of an input box.
How can I reference the newly added worksheet from code?

eg
dim sName as string
Sheets.Add
sName = inputbox("Enter sheet name")
Sheets("Sheet4").Select
Sheets("Sheet4").Name = sName

The only problem with this code, I think, is that the newly created
worksheet will not always be called "Sheet4" as it will always increment by
1. Is there a way to count the no. of worksheets in a workbook so that I
can have a variable in the code instead of "Sheet4"

Thanks
 
try
Sub addshandname()
mn = InputBox("Name")
Sheets.Add.Name = mn
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top