ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Rename the sheet just added (https://www.excelbanter.com/excel-programming/294962-rename-sheet-just-added.html)

Newbie

Rename the sheet just added
 
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



Don Guillett[_4_]

Rename the sheet just added
 
try
Sub addshandname()
mn = InputBox("Name")
Sheets.Add.Name = mn
End Sub

--
Don Guillett
SalesAid Software

"Newbie" wrote in message
...
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





Newbie

Rename the sheet just added
 
Thanks - works a treat

"Don Guillett" wrote in message
...
try
Sub addshandname()
mn = InputBox("Name")
Sheets.Add.Name = mn
End Sub

--
Don Guillett
SalesAid Software

"Newbie" wrote in message
...
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







Don Guillett[_4_]

Rename the sheet just added
 
glad to help

--
Don Guillett
SalesAid Software

"Newbie" wrote in message
...
Thanks - works a treat

"Don Guillett" wrote in message
...
try
Sub addshandname()
mn = InputBox("Name")
Sheets.Add.Name = mn
End Sub

--
Don Guillett
SalesAid Software

"Newbie" wrote in message
...
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










All times are GMT +1. The time now is 06:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com