Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 45
Default Renaming tabs from particular cell contents

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)

on error resume next
sh.Name = sh.Range("a2").Value
if err.number < 0 then
msgbox "Rename failed"
err.clear
end if
on error goto 0
End Sub


Let's Say you don't want it to give you an error if you have two tabs with
same name but you want it to go ahead and rename the tab with the same name
and insert (1),(2),..and so on after
the tab name.

How would you do this

Thanks




  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,722
Default Renaming tabs from particular cell contents

Could you use some sort of looping code, like this:


Dim EndNumber as String
On Error resume next
EndNumber = 0
sh.Name = sh.Range("a2").Value
Retest:
if err.number < 0 then
EndNumber=EndNumber + 1
sh.Name = sh.Range("a2").Value + "(" + EndNumber + ")"
goto Retest
end if

--
Best Regards,

Luke M


"scotty" wrote:

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)

on error resume next
sh.Name = sh.Range("a2").Value
if err.number < 0 then
msgbox "Rename failed"
err.clear
end if
on error goto 0
End Sub


Let's Say you don't want it to give you an error if you have two tabs with
same name but you want it to go ahead and rename the tab with the same name
and insert (1),(2),..and so on after
the tab name.

How would you do this

Thanks




  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,722
Default Renaming tabs from particular cell contents

Oops! Need to have

err.clear

before the Goto Retest line. Otherwise an infinite loop is created.
--
Best Regards,

Luke M


"Luke M" wrote:

Could you use some sort of looping code, like this:


Dim EndNumber as String
On Error resume next
EndNumber = 0
sh.Name = sh.Range("a2").Value
Retest:
if err.number < 0 then
EndNumber=EndNumber + 1
sh.Name = sh.Range("a2").Value + "(" + EndNumber + ")"
goto Retest
end if

--
Best Regards,

Luke M


"scotty" wrote:

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)

on error resume next
sh.Name = sh.Range("a2").Value
if err.number < 0 then
msgbox "Rename failed"
err.clear
end if
on error goto 0
End Sub


Let's Say you don't want it to give you an error if you have two tabs with
same name but you want it to go ahead and rename the tab with the same name
and insert (1),(2),..and so on after
the tab name.

How would you do this

Thanks




  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,722
Default Renaming tabs from particular cell contents

ARGH! Brain fart today.
SHOULD be...

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)

Dim EndNumber as String
On Error resume next
EndNumber = 0
sh.Name = sh.Range("a2").Value
Retest:
if err.number < 0 then
EndNumber=EndNumber + 1
err.clear
sh.Name = sh.Range("a2").Value + "(" + EndNumber + ")"
goto Retest
end if

end sub
--
Best Regards,

Luke M


"Luke M" wrote:

Could you use some sort of looping code, like this:


Dim EndNumber as String
On Error resume next
EndNumber = 0
sh.Name = sh.Range("a2").Value
Retest:
if err.number < 0 then
EndNumber=EndNumber + 1
sh.Name = sh.Range("a2").Value + "(" + EndNumber + ")"
goto Retest
end if

--
Best Regards,

Luke M


"scotty" wrote:

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)

on error resume next
sh.Name = sh.Range("a2").Value
if err.number < 0 then
msgbox "Rename failed"
err.clear
end if
on error goto 0
End Sub


Let's Say you don't want it to give you an error if you have two tabs with
same name but you want it to go ahead and rename the tab with the same name
and insert (1),(2),..and so on after
the tab name.

How would you do this

Thanks




  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 45
Default Renaming tabs from particular cell contents

Thanks for your help....but I couldn't get that to work. When I put that
code in and changed the value of the cell, the sheet1 name changed to that,
but when I went to sheet2 and changed the cell value to the same that was in
sheet1, the hourglass came up and wouldn't go off and then excel stopped
responding.

"Luke M" wrote:

ARGH! Brain fart today.
SHOULD be...

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)

Dim EndNumber as String
On Error resume next
EndNumber = 0
sh.Name = sh.Range("a2").Value
Retest:
if err.number < 0 then
EndNumber=EndNumber + 1
err.clear
sh.Name = sh.Range("a2").Value + "(" + EndNumber + ")"
goto Retest
end if

end sub
--
Best Regards,

Luke M


"Luke M" wrote:

Could you use some sort of looping code, like this:


Dim EndNumber as String
On Error resume next
EndNumber = 0
sh.Name = sh.Range("a2").Value
Retest:
if err.number < 0 then
EndNumber=EndNumber + 1
sh.Name = sh.Range("a2").Value + "(" + EndNumber + ")"
goto Retest
end if

--
Best Regards,

Luke M


"scotty" wrote:

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)

on error resume next
sh.Name = sh.Range("a2").Value
if err.number < 0 then
msgbox "Rename failed"
err.clear
end if
on error goto 0
End Sub

Let's Say you don't want it to give you an error if you have two tabs with
same name but you want it to go ahead and rename the tab with the same name
and insert (1),(2),..and so on after
the tab name.

How would you do this

Thanks






  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 45
Default Renaming tabs from particular cell contents

sorry..it does work when I am using letters, but when I am using numbers in
the cell, that is when Excel stops responding, until I press ESC.

How do I modify for numbers please


Thanks!!!

"scotty" wrote:

Thanks for your help....but I couldn't get that to work. When I put that
code in and changed the value of the cell, the sheet1 name changed to that,
but when I went to sheet2 and changed the cell value to the same that was in
sheet1, the hourglass came up and wouldn't go off and then excel stopped
responding.

"Luke M" wrote:

ARGH! Brain fart today.
SHOULD be...

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)

Dim EndNumber as String
On Error resume next
EndNumber = 0
sh.Name = sh.Range("a2").Value
Retest:
if err.number < 0 then
EndNumber=EndNumber + 1
err.clear
sh.Name = sh.Range("a2").Value + "(" + EndNumber + ")"
goto Retest
end if

end sub
--
Best Regards,

Luke M


"Luke M" wrote:

Could you use some sort of looping code, like this:


Dim EndNumber as String
On Error resume next
EndNumber = 0
sh.Name = sh.Range("a2").Value
Retest:
if err.number < 0 then
EndNumber=EndNumber + 1
sh.Name = sh.Range("a2").Value + "(" + EndNumber + ")"
goto Retest
end if

--
Best Regards,

Luke M


"scotty" wrote:

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)

on error resume next
sh.Name = sh.Range("a2").Value
if err.number < 0 then
msgbox "Rename failed"
err.clear
end if
on error goto 0
End Sub

Let's Say you don't want it to give you an error if you have two tabs with
same name but you want it to go ahead and rename the tab with the same name
and insert (1),(2),..and so on after
the tab name.

How would you do this

Thanks




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 Tabs Lakebum Excel Discussion (Misc queries) 3 December 26th 06 09:43 PM
renaming sheet tabs in a sequence Lee S Excel Worksheet Functions 1 May 25th 06 04:08 AM
renaming worksheet tabs calibronco Excel Discussion (Misc queries) 7 November 26th 05 01:02 AM
Hyperlinks and renaming tabs woolyhedgehog Excel Discussion (Misc queries) 0 October 18th 05 06:04 PM
Renaming Tabs ANDY73 Excel Discussion (Misc queries) 5 July 28th 05 09:42 AM


All times are GMT +1. The time now is 01:51 AM.

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"