PC Review


Reply
Thread Tools Rate Thread

Can a worksheet (tab) be renamed via a cell's value?

 
 
Michael Lanier
Guest
Posts: n/a
 
      11th Aug 2009
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
 
Reply With Quote
 
 
 
 
slarbie
Guest
Posts: n/a
 
      11th Aug 2009
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
>

 
Reply With Quote
 
arjen van...
Guest
Posts: n/a
 
      11th Aug 2009
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 With Quote
 
slarbie
Guest
Posts: n/a
 
      11th Aug 2009
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Protecting an Excel worksheet from being renamed JAC Microsoft Excel Programming 3 19th Sep 2008 11:53 AM
Hyperlink to renamed Worksheet fails KIM W Microsoft Excel Misc 2 7th Aug 2008 06:33 PM
In Office 2003 program worksheet can't be renamed due to .xls add. jamjar65 Microsoft Excel Misc 1 10th Apr 2008 12:10 PM
Re: Formula changes to renamed cell name. I want to keep it from chang Dave Peterson Microsoft Excel Misc 0 22nd Jan 2007 02:39 PM
toolbar macros that dont change when worksheet is renamed =?Utf-8?B?bWFybGluNDA=?= Microsoft Excel New Users 1 21st Nov 2005 07:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:45 PM.