Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Rename Worksheets Based on Values in cells

Hi All,

I would really appreciate some help with the following:

I have a workbook with a worksheet called "Control"
In cells A1 through to A31 I have each of the days of the
month of January listed for example January 1 is in cell A1 and
in cell A2 the words January 2 etc.

The workbook also contains 31 additional worksheets which I would
like to be linked to the names in cells A1 to A31 on the "control sheet"
so the first worksheet after the control worksheet will be named January 1
etc.

If I change the names in A1 to A31 to February 1 for example I would
like the sheets to automatically be remained according to the new text.

Any ideas on how to accomplish the above?
All suggestions welcome.

Thanks,

Steve


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Rename Worksheets Based on Values in cells

There is probably a better way of doing this but this works and is rather
secure.

1 - Get a workbbok with the required number of worksheets (at least 32)
2 - In the VB Editor, go to Tools-Reference and select Microsoft Visual
Basic for Applications Extensibility 5.3 (or whatever version you have)
3 - Rename the codename of all you worksheets to Control, Day1, Day2,
Day3...Day31. Each sheet has two names. The codename appears as (Name) in the
properties window.
4 - Paste this code in the code section of the Control sheet.

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

Dim MySheet As String

Application.ScreenUpdating = False

If Not Intersect(Target, Range("Dates")) Is Nothing Then
MySheet = "Day" & Target.Row
ThisWorkbook.VBProject.VBComponents(MySheet).Activ ate
If Target.Value = "" Then
ActiveSheet.Name = "No " & MySheet
Else
ActiveSheet.Name = Target.Text
End If
End If

Control.Activate

Application.ScreenUpdating = True

End Sub

5 - Apply the name 'Dates' to the range A1 to A31 on the Control sheet

Hope this Helps and that I explained myself well enough. The use of codename
should help with ensuring that manual changes to the name by mistake don't
effect the code.


--
Cheers!

Richard Reye

"Never argue with an idiot. They'll bring you down to their level then beat
you with experience" - someone


"Steve" wrote:

Hi All,

I would really appreciate some help with the following:

I have a workbook with a worksheet called "Control"
In cells A1 through to A31 I have each of the days of the
month of January listed for example January 1 is in cell A1 and
in cell A2 the words January 2 etc.

The workbook also contains 31 additional worksheets which I would
like to be linked to the names in cells A1 to A31 on the "control sheet"
so the first worksheet after the control worksheet will be named January 1
etc.

If I change the names in A1 to A31 to February 1 for example I would
like the sheets to automatically be remained according to the new text.

Any ideas on how to accomplish the above?
All suggestions welcome.

Thanks,

Steve



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Rename Worksheets Based on Values in cells

Change of Code. The following code will allow for drag'n'drop (Autofill??).
That is, if the target area (area changed) is more than one cell, it won't
through an error!

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

Dim MySheet As String
Dim Cell As Range

Application.ScreenUpdating = False

If Not Intersect(Target, Range("Dates")) Is Nothing Then
For Each Cell In Target
MySheet = "Day" & Cell.Row
ThisWorkbook.VBProject.VBComponents(MySheet).Activ ate
If Cell.Value = "" Then
ActiveSheet.Name = "No " & MySheet
Else
ActiveSheet.Name = Cell.Text
End If
Next Cell
End If

Control.Activate

Application.ScreenUpdating = True

End Sub


--
Cheers!

Richard Reye

"Never argue with an idiot. They'll bring you down to their level then beat
you with experience" - someone


"Steve" wrote:

Hi All,

I would really appreciate some help with the following:

I have a workbook with a worksheet called "Control"
In cells A1 through to A31 I have each of the days of the
month of January listed for example January 1 is in cell A1 and
in cell A2 the words January 2 etc.

The workbook also contains 31 additional worksheets which I would
like to be linked to the names in cells A1 to A31 on the "control sheet"
so the first worksheet after the control worksheet will be named January 1
etc.

If I change the names in A1 to A31 to February 1 for example I would
like the sheets to automatically be remained according to the new text.

Any ideas on how to accomplish the above?
All suggestions welcome.

Thanks,

Steve



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Rename Worksheets Based on Values in cells

This is a variant on an FAQ. The solution here can be modified to apply
to different sheets' names:

http://www.mcgimpsey.com/excel/event...efromcell.html

You can find lots of other suggestions in the archives:

http://groups.google.com/advanced_group_search



In article <xQg9f.359077$oW2.279554@pd7tw1no,
"Steve" wrote:

Hi All,

I would really appreciate some help with the following:

I have a workbook with a worksheet called "Control"
In cells A1 through to A31 I have each of the days of the
month of January listed for example January 1 is in cell A1 and
in cell A2 the words January 2 etc.

The workbook also contains 31 additional worksheets which I would
like to be linked to the names in cells A1 to A31 on the "control sheet"
so the first worksheet after the control worksheet will be named January 1
etc.

If I change the names in A1 to A31 to February 1 for example I would
like the sheets to automatically be remained according to the new text.

Any ideas on how to accomplish the above?
All suggestions welcome.

Thanks,

Steve

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Rename Worksheets Based on Values in cells

Please excuse my spelling mistakes!

--
Cheers!

Richard Reye

"Never argue with an idiot. They'll bring you down to their level then beat
you with experience" - someone


"Richard Reye" wrote:

Change of Code. The following code will allow for drag'n'drop (Autofill??).
That is, if the target area (area changed) is more than one cell, it won't
through an error!

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

Dim MySheet As String
Dim Cell As Range

Application.ScreenUpdating = False

If Not Intersect(Target, Range("Dates")) Is Nothing Then
For Each Cell In Target
MySheet = "Day" & Cell.Row
ThisWorkbook.VBProject.VBComponents(MySheet).Activ ate
If Cell.Value = "" Then
ActiveSheet.Name = "No " & MySheet
Else
ActiveSheet.Name = Cell.Text
End If
Next Cell
End If

Control.Activate

Application.ScreenUpdating = True

End Sub


--
Cheers!

Richard Reye

"Never argue with an idiot. They'll bring you down to their level then beat
you with experience" - someone


"Steve" wrote:

Hi All,

I would really appreciate some help with the following:

I have a workbook with a worksheet called "Control"
In cells A1 through to A31 I have each of the days of the
month of January listed for example January 1 is in cell A1 and
in cell A2 the words January 2 etc.

The workbook also contains 31 additional worksheets which I would
like to be linked to the names in cells A1 to A31 on the "control sheet"
so the first worksheet after the control worksheet will be named January 1
etc.

If I change the names in A1 to A31 to February 1 for example I would
like the sheets to automatically be remained according to the new text.

Any ideas on how to accomplish the above?
All suggestions welcome.

Thanks,

Steve





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Rename Worksheets Based on Values in cells

This assumes that the Control worksheet is the first sheet in the worksheets
collection - i.e. can be refered to as Sheet(1). The sheets that have dates
for names can likewise be refered to as Sheet(2), Sheet(3) etc. Also assumed
is that you are changing the text in cells A1:A31 individually as opposed to
batch changing by macro or other means. You likely will need to format the
cells A1:A31 as Text else you may get an error if Excel tries to convert it
to a date format containing illegal characters (e.g. "/" or "-").

Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Intersect(Target, Range("A1:A31")) Is Nothing Then Exit Sub
Sheets(Target.Row + 1).Name = Target.Value
On Error GoTo 0
End Sub

Regards,
Greg

"Steve" wrote:

Hi All,

I would really appreciate some help with the following:

I have a workbook with a worksheet called "Control"
In cells A1 through to A31 I have each of the days of the
month of January listed for example January 1 is in cell A1 and
in cell A2 the words January 2 etc.

The workbook also contains 31 additional worksheets which I would
like to be linked to the names in cells A1 to A31 on the "control sheet"
so the first worksheet after the control worksheet will be named January 1
etc.

If I change the names in A1 to A31 to February 1 for example I would
like the sheets to automatically be remained according to the new text.

Any ideas on how to accomplish the above?
All suggestions welcome.

Thanks,

Steve



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Rename Worksheets Based on Values in cells


Hello Steve,

For this code to run properly, "Control" must be the name of the
Leftmost Worksheet Tab. This will be the first Worksheet created in the
collection. The Worksheet names can change, but order of creation does
not.

Add this code into "Control's" Worksheet Events code.


Code:
--------------------
Private Sub Worksheet_Change(ByVal Target As Range)

Dim C As Long
Dim R As Long

'Change the Worksheet name to the value in cell A1 to A31
'When the cell's contents are changed.
'This code must be placed the First Worksheet (Leftmost Tab).

On Error GoTo NameFault

With Target
C = .Column
R = .Row
End With

If C = 1 And (R = 1 And R <= 31) Then
Worksheets(R + 1).Name = Target.Value
End If

Exit Sub

NameFault:
Msg = "Error " & Err.Number & vbCrLf _
& Err.Description
MsgBox Msg, vbExclamation + vbOKOnly

End Sub

--------------------

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=480502

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
Summing based on values in other worksheets chickalina Excel Worksheet Functions 2 March 17th 09 12:57 PM
Macro to Create Worksheets Based on Cell Values Lilbit Excel Worksheet Functions 3 March 24th 08 05:39 PM
conditional formating cells i Excel based on other cells values Elias Petursson Excel Worksheet Functions 3 May 23rd 06 06:45 PM
Rename worksheets Senjaya Excel Programming 3 April 19th 05 02:07 PM
Create Worksheets Based Upon Changing Column Values in XP Gary[_12_] Excel Programming 1 December 18th 03 12:07 AM


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

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"