#1   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default renaming

I am trying to name the current sheet to the value of the
activecell. The code below is what I am using and it adds
an additional number rather than renumbering the sheet
that I am naming if the sheet already exists. Such as
Name1 the next would be Name12 the next would be Name123
then Name1234, how can I fix the code to a form like Name1
then Name2 then Name3 -- Similar to the way Excel does
this with sheets.

Thank You



strNewName = ActiveCell.Value

i = 0
newsh:
i = (i + 1)
strNewName = strNewName & i
For Each wks In ThisWorkbook.Worksheets
If wks.Name = strNewName Then
GoTo newsh:
ActiveSheet.Name = strNewName
blnDuplicate = True
End If
Next wks
If blnDuplicate = False Then
ActiveSheet.Name = strNewName
End If
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default renaming

hi,
your sheet is name1. in the loop you have strNewName =
name1 & i. I think that is your problem
you will have to truncate the Name1 to Name.
look up the trunc function and the trim function in vb help
regards
Frank
-----Original Message-----
I am trying to name the current sheet to the value of the
activecell. The code below is what I am using and it adds
an additional number rather than renumbering the sheet
that I am naming if the sheet already exists. Such as
Name1 the next would be Name12 the next would be Name123
then Name1234, how can I fix the code to a form like

Name1
then Name2 then Name3 -- Similar to the way Excel does
this with sheets.

Thank You



strNewName = ActiveCell.Value

i = 0
newsh:
i = (i + 1)
strNewName = strNewName & i
For Each wks In ThisWorkbook.Worksheets
If wks.Name = strNewName Then
GoTo newsh:
ActiveSheet.Name = strNewName
blnDuplicate = True
End If
Next wks
If blnDuplicate = False Then
ActiveSheet.Name = strNewName
End If
.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Renaming worksheets James Excel Worksheet Functions 0 May 12th 09 11:45 PM
Worksheet renaming jwilliam33 Excel Discussion (Misc queries) 5 December 6th 08 09:14 PM
Renaming folders Robin Clay[_3_] Excel Programming 6 August 12th 04 05:12 PM
Renaming ianripping[_66_] Excel Programming 3 May 22nd 04 12:02 PM
Renaming within VBA Brent McIntyre Excel Programming 4 August 21st 03 02:10 AM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"