Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Can a worksheet (tab) be renamed via a cell's value?

I would like to be able to rename a worksheet according to the
returned value of a cell. For example, if Sheet1 A1=1, then Sheet2 is
named "Red." When the same Sheet1 A1=2, then Sheet2 is renamed
"Green." Is this possible? Thanks for your help.

Michael
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Can a worksheet (tab) be renamed via a cell's value?

Right-click your Sheet1 tab and select "View Code". Then paste in the code
below. Add more "cases" for more number-color combinations.

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo No2
If Target.Address = "$A$1" Then
Select Case Target.Value
Case 1
Sheets(2).Name = "Red"
Case 2
Sheets(2).Name = "Green"
End Select
End If

No2:
On Error GoTo 0

End Sub


"Michael Lanier" wrote:

I would like to be able to rename a worksheet according to the
returned value of a cell. For example, if Sheet1 A1=1, then Sheet2 is
named "Red." When the same Sheet1 A1=2, then Sheet2 is renamed
"Green." Is this possible? Thanks for your help.

Michael

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Can a worksheet (tab) be renamed via a cell's value?

Another way to use a worksheet change event:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Sheet1.Range("A1").Value = 1 Then
Sheet2.Name = "Red"
ElseIf Sheet1.Range("A1").Value = 2 Then
Sheet2.Name = "Green"
Else
MsgBox ("no name for that value")
End If

End Sub
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Can a worksheet (tab) be renamed via a cell's value?

That works too - but it does seem like a good idea to account for the
possibility there is no Sheet2, thus the error handler I included...

Another thought might be to put some validation on the a1 input cell...

"arjen van..." wrote:

Another way to use a worksheet change event:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Sheet1.Range("A1").Value = 1 Then
Sheet2.Name = "Red"
ElseIf Sheet1.Range("A1").Value = 2 Then
Sheet2.Name = "Green"
Else
MsgBox ("no name for that value")
End If

End Sub

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
Protecting an Excel worksheet from being renamed JAC Excel Programming 3 September 19th 08 11:53 AM
Hyperlink to renamed Worksheet fails KIM W Excel Discussion (Misc queries) 2 August 7th 08 06:33 PM
In Office 2003 program worksheet can't be renamed due to .xls add. jamjar65 Excel Discussion (Misc queries) 1 April 10th 08 12:10 PM
How can I include a cell's value in a worksheet header? BillSea Excel Programming 1 November 23rd 05 04:33 AM
toolbar macros that dont change when worksheet is renamed marlin40 New Users to Excel 1 November 21st 05 07:25 PM


All times are GMT +1. The time now is 05:53 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"