#1   Report Post  
Posted to microsoft.public.excel.misc
Han Han is offline
external usenet poster
 
Posts: 4
Default Tab sheet name

I have this code,
Private Sub Worksheet_Calculate()
Me.Name = Range("b36").Value
End Sub
that name the sheet tab based on cell B36. The problem is when I copy the
sheet and I enter the same name in the duplicate sheet and the previous sheet
I get an error. Is there a way to add a nuber at the end of the duplicate
sheet.
example:
1st sheet name = Round
2nd sheet name = square
3rd sheet name = round(2)
all sheet have the same calculations.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 364
Default Tab sheet name

Try
'-----------------
Private Sub Worksheet_Calculate()
Dim strName
Dim j
j = 0
strName = Range("b36").Value
For Each ws In Worksheets
If (strName = ws.Name) Then
j = 2
End If
Next ws
If j 0 Then
strName = strName & "(" & j & ")"
End If
Me.Name = strName
End Sub
'-----------------

This will name the sheet as round(2) if round already exists
but will fail if round(2) exists.
You need to expand it to test for this condition, take the highest number
and add one to it...
"Han" wrote:

I have this code,
Private Sub Worksheet_Calculate()
Me.Name = Range("b36").Value
End Sub
that name the sheet tab based on cell B36. The problem is when I copy the
sheet and I enter the same name in the duplicate sheet and the previous sheet
I get an error. Is there a way to add a nuber at the end of the duplicate
sheet.
example:
1st sheet name = Round
2nd sheet name = square
3rd sheet name = round(2)
all sheet have the same calculations.

  #3   Report Post  
Posted to microsoft.public.excel.misc
Han Han is offline
external usenet poster
 
Posts: 4
Default Tab sheet name

Code kinda works. Sometimes I copy the 1st sheet several times and give it
the same name because the same calcs are performed but for different
scenerios. I don't know if i'm being clear enough.
Here's another example that might clear things up.
1st sheet calcs volumn of a cylinder (sheet name = cylinder)
2nd sheet calcs volumn of cylinder of different height and radius (sheet
name = cylinder (2)
3rd sheet calcs volumn of cylinder of yet different height and radius (sheet
name = cylinder (3)

"Sheeloo" wrote:

Try
'-----------------
Private Sub Worksheet_Calculate()
Dim strName
Dim j
j = 0
strName = Range("b36").Value
For Each ws In Worksheets
If (strName = ws.Name) Then
j = 2
End If
Next ws
If j 0 Then
strName = strName & "(" & j & ")"
End If
Me.Name = strName
End Sub
'-----------------

This will name the sheet as round(2) if round already exists
but will fail if round(2) exists.
You need to expand it to test for this condition, take the highest number
and add one to it...
"Han" wrote:

I have this code,
Private Sub Worksheet_Calculate()
Me.Name = Range("b36").Value
End Sub
that name the sheet tab based on cell B36. The problem is when I copy the
sheet and I enter the same name in the duplicate sheet and the previous sheet
I get an error. Is there a way to add a nuber at the end of the duplicate
sheet.
example:
1st sheet name = Round
2nd sheet name = square
3rd sheet name = round(2)
all sheet have the same calculations.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 364
Default Tab sheet name

Your requirement was clear... that is why I said "You need to expand it to
test for this condition, take the highest number
and add one to it... "

"Han" wrote:

Code kinda works. Sometimes I copy the 1st sheet several times and give it
the same name because the same calcs are performed but for different
scenerios. I don't know if i'm being clear enough.
Here's another example that might clear things up.
1st sheet calcs volumn of a cylinder (sheet name = cylinder)
2nd sheet calcs volumn of cylinder of different height and radius (sheet
name = cylinder (2)
3rd sheet calcs volumn of cylinder of yet different height and radius (sheet
name = cylinder (3)

"Sheeloo" wrote:

Try
'-----------------
Private Sub Worksheet_Calculate()
Dim strName
Dim j
j = 0
strName = Range("b36").Value
For Each ws In Worksheets
If (strName = ws.Name) Then
j = 2
End If
Next ws
If j 0 Then
strName = strName & "(" & j & ")"
End If
Me.Name = strName
End Sub
'-----------------

This will name the sheet as round(2) if round already exists
but will fail if round(2) exists.
You need to expand it to test for this condition, take the highest number
and add one to it...
"Han" wrote:

I have this code,
Private Sub Worksheet_Calculate()
Me.Name = Range("b36").Value
End Sub
that name the sheet tab based on cell B36. The problem is when I copy the
sheet and I enter the same name in the duplicate sheet and the previous sheet
I get an error. Is there a way to add a nuber at the end of the duplicate
sheet.
example:
1st sheet name = Round
2nd sheet name = square
3rd sheet name = round(2)
all sheet have the same calculations.

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
Duplicate sheet, autonumber sheet, record data on another sheet des-sa[_2_] Excel Worksheet Functions 0 May 8th 08 06:56 PM
lookup single value in one sheet, return multiple results from theother sheet Chuck[_3_] Excel Worksheet Functions 1 April 4th 08 06:17 AM
"='sheet 1'!D4" auto fill sheet to sheet ='sheet 2'!D4 mistewalker Excel Worksheet Functions 5 January 6th 08 11:36 PM
How do I select price from sheet.b where sheet.a part no = sheet.b Sonny Excel Worksheet Functions 4 April 4th 06 05:08 PM
relative sheet references ala sheet(-1)!B11 so I can copy a sheet. RonMc5 Excel Discussion (Misc queries) 9 February 3rd 05 12:51 AM


All times are GMT +1. The time now is 10:03 PM.

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

About Us

"It's about Microsoft Excel"