Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Worsheet Name Change Based on cell's value

Hello
I want to automatically change the name of a worksheet based on th
value of cell K5 when the value of cell K5 changes. I currently hav
cell K5 refering to the value of a cell in another Worksheet. Is ther
a way to automatically rename a sheet based on the formula result of
cell within that worksheet?

Thank you
Edwar

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Worsheet Name Change Based on cell's value

Hi
try the following macro. Put this in your worksheet module (not in a
standard module):
Private Sub Worksheet_Calculate()
Static old_cell As Variant

On Error GoTo errhandler
If IsEmpty(old_cell) Then
old_cell = Me.Range("K5").Value
End If

With Me.Range("K5")
If .Value < old_cell Then
Application.EnableEvents = False
Me.Name = .Value
old_cell = .Value
End If
End With

errhandler:
Application.EnableEvents = True
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany


Hello
I want to automatically change the name of a worksheet based on the
value of cell K5 when the value of cell K5 changes. I currently have
cell K5 refering to the value of a cell in another Worksheet. Is

there
a way to automatically rename a sheet based on the formula result of

a
cell within that worksheet?

Thank you
Edward


---
Message posted from http://www.ExcelForum.com/


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Worsheet Name Change Based on cell's value

You can use the worksheet calculate event:
Note that I had to qualify the sheet with an index number.
Also made provision if K5 = 0

''''''''''''''''''''''
Private Sub Worksheet_Calculate()
If Sheets(3).Range("K5") < 0 Then
If Sheets(3).Name < Sheets(3).Range("K5") Then
Sheets(3).Name = Range("K5")
End If
End If
End Sub
'''''''''''''''''''''''''
hth
--

steveB

(Remove 'NOSPAM' from email address if contacting me direct)


"nuver " wrote in message
...
Hello
I want to automatically change the name of a worksheet based on the
value of cell K5 when the value of cell K5 changes. I currently have
cell K5 refering to the value of a cell in another Worksheet. Is there
a way to automatically rename a sheet based on the formula result of a
cell within that worksheet?

Thank you
Edward


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Worsheet Name Change Based on cell's value

Hi
you should disable event before changing the worksheet name as this
could cause also a new worksheet_claculate event

--
Regards
Frank Kabel
Frankfurt, Germany


steveB wrote:
You can use the worksheet calculate event:
Note that I had to qualify the sheet with an index number.
Also made provision if K5 = 0

''''''''''''''''''''''
Private Sub Worksheet_Calculate()
If Sheets(3).Range("K5") < 0 Then
If Sheets(3).Name < Sheets(3).Range("K5") Then
Sheets(3).Name = Range("K5")
End If
End If
End Sub
'''''''''''''''''''''''''
hth

"nuver " wrote in message
...
Hello
I want to automatically change the name of a worksheet based on the
value of cell K5 when the value of cell K5 changes. I currently have
cell K5 refering to the value of a cell in another Worksheet. Is
there a way to automatically rename a sheet based on the formula
result of a cell within that worksheet?

Thank you
Edward


---
Message posted from http://www.ExcelForum.com/


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Worsheet Name Change Based on cell's value

Thank you Frank but I could not get the code to work. I pasted your cod
in the Worsheet module but it does not change the name of th
worksheet.

Steve I pasted your code and it did work for the 3rd sheet in th
workbook so I simply changed the index number to 2 and it worked on th
sheet I was trying to change. If I make a copy of the sheet then I nee
to go into the code and manually change the index, is there a way t
make this automatic when I creat a copy of the worksheet?

Thank you both for your advice and quick response

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Worsheet Name Change Based on cell's value

Frank,

Thanks! Didn't include that since the code was looking to see if the name
needed changing and it all happens pretty fast. But it would seem to be
good form to include the disable.

--

steveB

(Remove 'NOSPAM' from email address if contacting me direct)


"Frank Kabel" wrote in message
...
Hi
you should disable event before changing the worksheet name as this
could cause also a new worksheet_claculate event

--
Regards
Frank Kabel
Frankfurt, Germany


steveB wrote:
You can use the worksheet calculate event:
Note that I had to qualify the sheet with an index number.
Also made provision if K5 = 0

''''''''''''''''''''''
Private Sub Worksheet_Calculate()
If Sheets(3).Range("K5") < 0 Then
If Sheets(3).Name < Sheets(3).Range("K5") Then
Sheets(3).Name = Range("K5")
End If
End If
End Sub
'''''''''''''''''''''''''
hth

"nuver " wrote in message
...
Hello
I want to automatically change the name of a worksheet based on the
value of cell K5 when the value of cell K5 changes. I currently have
cell K5 refering to the value of a cell in another Worksheet. Is
there a way to automatically rename a sheet based on the formula
result of a cell within that worksheet?

Thank you
Edward


---
Message posted from http://www.ExcelForum.com/




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Worsheet Name Change Based on cell's value

Hi
you have to paste this code into the worksheet for which the name has
to be changed. It checks cell K5 on this sheet

--
Regards
Frank Kabel
Frankfurt, Germany


Thank you Frank but I could not get the code to work. I pasted your
code in the Worsheet module but it does not change the name of the
worksheet.

Steve I pasted your code and it did work for the 3rd sheet in the
workbook so I simply changed the index number to 2 and it worked on
the sheet I was trying to change. If I make a copy of the sheet then
I need to go into the code and manually change the index, is there a
way to make this automatic when I creat a copy of the worksheet?

Thank you both for your advice and quick response.


---
Message posted from http://www.ExcelForum.com/


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Worsheet Name Change Based on cell's value

You could use the Code name of the sheet. This only gets changed from VB
Editor (or in code) - it is not the name on the sheet tab (this code only
changes the name on the tab). Just check the VB Editor to get the correct
code name.

But now you have reached my ceiling. I know that ThisWorkbook refers to the
workbook containing the code. Not sure what the eqivalent is for ThisSheet
(not found).

Maybe Frank can give us a clue of how to deal with this when you copy the
worksheet.

''''''''''''''''''''
Private Sub Worksheet_Calculate()
Application.EnableEvents = False

If Sheet2.Range("K5") < 0 Then
If Sheet2.Name < Sheet2.Range("K5") Then
Sheet2.Name = Range("K5")
End If
End If

Application.EnableEvents = True
End Sub
'''''''''''''''''''''''''''''

hth
--

steveB

(Remove 'NOSPAM' from email address if contacting me direct)


"nuver " wrote in message
...
Thank you Frank but I could not get the code to work. I pasted your code
in the Worsheet module but it does not change the name of the
worksheet.

Steve I pasted your code and it did work for the 3rd sheet in the
workbook so I simply changed the index number to 2 and it worked on the
sheet I was trying to change. If I make a copy of the sheet then I need
to go into the code and manually change the index, is there a way to
make this automatic when I creat a copy of the worksheet?

Thank you both for your advice and quick response.


---
Message posted from http://www.ExcelForum.com/



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Worsheet Name Change Based on cell's value

Hi
within a worksheet event simply use
me
this refers to the sheet the worksheet event resides in.
e.g.
sub worksheet_calculate()
msgbox me.name
end sub

--
Regards
Frank Kabel
Frankfurt, Germany


steveB wrote:
You could use the Code name of the sheet. This only gets changed
from VB Editor (or in code) - it is not the name on the sheet tab
(this code only changes the name on the tab). Just check the VB
Editor to get the correct code name.

But now you have reached my ceiling. I know that ThisWorkbook refers
to the workbook containing the code. Not sure what the eqivalent is
for ThisSheet (not found).

Maybe Frank can give us a clue of how to deal with this when you copy
the worksheet.

''''''''''''''''''''
Private Sub Worksheet_Calculate()
Application.EnableEvents = False

If Sheet2.Range("K5") < 0 Then
If Sheet2.Name < Sheet2.Range("K5") Then
Sheet2.Name = Range("K5")
End If
End If

Application.EnableEvents = True
End Sub
'''''''''''''''''''''''''''''

hth

"nuver " wrote in message
...
Thank you Frank but I could not get the code to work. I pasted your
code in the Worsheet module but it does not change the name of the
worksheet.

Steve I pasted your code and it did work for the 3rd sheet in the
workbook so I simply changed the index number to 2 and it worked on
the sheet I was trying to change. If I make a copy of the sheet then
I need to go into the code and manually change the index, is there a
way to make this automatic when I creat a copy of the worksheet?

Thank you both for your advice and quick response.


---
Message posted from http://www.ExcelForum.com/


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Worsheet Name Change Based on cell's value

Frank,

Thanks again! Keep forgetting about "me". (and I am so narcissistic, too)

--

steveB

(Remove 'NOSPAM' from email address if contacting me direct)


"Frank Kabel" wrote in message
...
Hi
within a worksheet event simply use
me
this refers to the sheet the worksheet event resides in.
e.g.
sub worksheet_calculate()
msgbox me.name
end sub

--
Regards
Frank Kabel
Frankfurt, Germany


steveB wrote:
You could use the Code name of the sheet. This only gets changed
from VB Editor (or in code) - it is not the name on the sheet tab
(this code only changes the name on the tab). Just check the VB
Editor to get the correct code name.

But now you have reached my ceiling. I know that ThisWorkbook refers
to the workbook containing the code. Not sure what the eqivalent is
for ThisSheet (not found).

Maybe Frank can give us a clue of how to deal with this when you copy
the worksheet.

''''''''''''''''''''
Private Sub Worksheet_Calculate()
Application.EnableEvents = False

If Sheet2.Range("K5") < 0 Then
If Sheet2.Name < Sheet2.Range("K5") Then
Sheet2.Name = Range("K5")
End If
End If

Application.EnableEvents = True
End Sub
'''''''''''''''''''''''''''''

hth

"nuver " wrote in message
...
Thank you Frank but I could not get the code to work. I pasted your
code in the Worsheet module but it does not change the name of the
worksheet.

Steve I pasted your code and it did work for the 3rd sheet in the
workbook so I simply changed the index number to 2 and it worked on
the sheet I was trying to change. If I make a copy of the sheet then
I need to go into the code and manually change the index, is there a
way to make this automatic when I creat a copy of the worksheet?

Thank you both for your advice and quick response.


---
Message posted from http://www.ExcelForum.com/






  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Worsheet Name Change Based on cell's value

Thank you both for all of your help. I am getting closer to getting thi
code to work but this is my first attempt working with code.
I tried the code below replacing Sheet2. with me. but now I can not ge
it to work at all. When you get a chance could you please let me kno
what I am doing wrong. Sorry to be such a pest.

Private Sub Worksheet_Calculate()
Application.EnableEvents = False

If Me.Range("K5") < 0 Then
If Me.Name < Me.Range("K5") Then
Me.Name = Range("K5")
End If
End If

Application.EnableEvents = True
End Su

--
Message posted from http://www.ExcelForum.com

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Worsheet Name Change Based on cell's value

Private Sub Worksheet_Calculate()
Application.EnableEvents = False

On Error Resume Next
Me.Name = me.Range("K5").Value

Application.EnableEvents = True
End Sub

--
Regards,
Tom Ogilvy


"nuver " wrote in message
...
Thank you both for all of your help. I am getting closer to getting this
code to work but this is my first attempt working with code.
I tried the code below replacing Sheet2. with me. but now I can not get
it to work at all. When you get a chance could you please let me know
what I am doing wrong. Sorry to be such a pest.

Private Sub Worksheet_Calculate()
Application.EnableEvents = False

If Me.Range("K5") < 0 Then
If Me.Name < Me.Range("K5") Then
Me.Name = Range("K5")
End If
End If

Application.EnableEvents = True
End Sub


---
Message posted from http://www.ExcelForum.com/



  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Worsheet Name Change Based on cell's value

Worked like a charm. Thank you all very much! You just saved me a lot o
tedious work.


E

--
Message posted from http://www.ExcelForum.com

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
Change one cell's format based on value of another without cond fm JoAnn New Users to Excel 4 April 9th 08 04:00 PM
Have row color change to one of 8 different colors based on one cell's value (I, O, C, T, L, E, X, A) Mel Excel Discussion (Misc queries) 8 October 6th 06 03:16 PM
Conditional Format based on other cell's value Stella Excel Worksheet Functions 1 June 23rd 06 06:46 PM
change format of cells (bold, italic) based on one cell's answer Jabi Excel Discussion (Misc queries) 4 May 25th 06 12:33 PM
Change value based on another cell's value mainemike Excel Discussion (Misc queries) 1 March 7th 06 06:36 PM


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