ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   adding a sheet and renaming (https://www.excelbanter.com/excel-programming/357492-adding-sheet-renaming.html)

oercim

adding a sheet and renaming
 
Hello. With excel macro, I want to add a sheet and rename the
sheet but the name is not specific, it is a variable. For example,

Sub b()
Sheets.Add.Name = "aaaa"
End Sub

works fine but here , the sheet name is not variable, it is
specific named "aaaa",
However, the below gives error

Sub b()
Dim a As String
a = "aaaa"
Sheets.Add.Name = a
End Sub

What can I do? Thanks alot.


Bob Phillips[_6_]

adding a sheet and renaming
 
Works fine for me. It will fail if that sheet already exists.

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"oercim" wrote in message
oups.com...
Hello. With excel macro, I want to add a sheet and rename the
sheet but the name is not specific, it is a variable. For example,

Sub b()
Sheets.Add.Name = "aaaa"
End Sub

works fine but here , the sheet name is not variable, it is
specific named "aaaa",
However, the below gives error

Sub b()
Dim a As String
a = "aaaa"
Sheets.Add.Name = a
End Sub

What can I do? Thanks alot.




oercim

adding a sheet and renaming
 
OK. sorry, it works fine for me too. Thanks alot.



All times are GMT +1. The time now is 02:16 PM.

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