Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Auto Naming Worksheets

I have a workbook that has multiple worksheets. I would like to name the
worksheets and used a macro that I found in one of the threads:

Sub name_sheets()
For Each ws In Worksheets
ws.Name = ws.Range("A1").Value
Next
End Sub

The macro works great but their are some A1 cells in some of the sheets that
will not be named until the user completes a master form and the name is
filtered to the corresponding sheet.

Being new to the macro world, how can I have the macro skip the sheets that
have a 'null' value in A1?





  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Auto Naming Worksheets

Sub name_sheets()
For Each ws In Worksheets
If Trim(ws.Range("A1")) < "" ws.Name = ws.Range("A1").Value
Next
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"Will Cendrowski" wrote:

I have a workbook that has multiple worksheets. I would like to name the
worksheets and used a macro that I found in one of the threads:

Sub name_sheets()
For Each ws In Worksheets
ws.Name = ws.Range("A1").Value
Next
End Sub

The macro works great but their are some A1 cells in some of the sheets that
will not be named until the user completes a master form and the name is
filtered to the corresponding sheet.

Being new to the macro world, how can I have the macro skip the sheets that
have a 'null' value in A1?





  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Auto Naming Worksheets

Hi,

A null value will generate an error so use this

Sub name_sheets()
On Error Resume Next
For Each ws In Worksheets
ws.Name = ws.Range("A1").Value
Next
End Sub

Mike

"Will Cendrowski" wrote:

I have a workbook that has multiple worksheets. I would like to name the
worksheets and used a macro that I found in one of the threads:

Sub name_sheets()
For Each ws In Worksheets
ws.Name = ws.Range("A1").Value
Next
End Sub

The macro works great but their are some A1 cells in some of the sheets that
will not be named until the user completes a master form and the name is
filtered to the corresponding sheet.

Being new to the macro world, how can I have the macro skip the sheets that
have a 'null' value in A1?





  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Auto Naming Worksheets

Check replies at your post from yesterday.

Will Cendrowski wrote:

I have a workbook that has multiple worksheets. I would like to name the
worksheets and used a macro that I found in one of the threads:

Sub name_sheets()
For Each ws In Worksheets
ws.Name = ws.Range("A1").Value
Next
End Sub

The macro works great but their are some A1 cells in some of the sheets that
will not be named until the user completes a master form and the name is
filtered to the corresponding sheet.

Being new to the macro world, how can I have the macro skip the sheets that
have a 'null' value in A1?


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Auto Naming Worksheets

You can use the worksheet change event so that the tab name can be renamed as
an when the user change the cell A1 in the sheet.. From workbook press
Alt+F11 to launch VBE (Visual Basic Editor). From the left treeview search
for the workbook name and click on + to expand it. Within that you should see
the following

VBAProject(Your_Filename)
Microsoft Excel Objects
Sheet1(Sheet1)
Sheet2(Sheet2)
Sheet3(Sheet3)
This Workbook

Double click 'This WorkBook' and paste the below code to the right code pane.

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Count = 1 And Target.Address = "$A$1" Then
Application.EnableEvents = False
If Trim(Target.Text) < "" Then Sh.Name = Trim(Range("A1"))
Application.EnableEvents = True
End If
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Sub name_sheets()
For Each ws In Worksheets
If Trim(ws.Range("A1")) < "" ws.Name = ws.Range("A1").Value
Next
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"Will Cendrowski" wrote:

I have a workbook that has multiple worksheets. I would like to name the
worksheets and used a macro that I found in one of the threads:

Sub name_sheets()
For Each ws In Worksheets
ws.Name = ws.Range("A1").Value
Next
End Sub

The macro works great but their are some A1 cells in some of the sheets that
will not be named until the user completes a master form and the name is
filtered to the corresponding sheet.

Being new to the macro world, how can I have the macro skip the sheets that
have a 'null' value in A1?





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
Auto naming Worksheets Will Cendrowski Excel Discussion (Misc queries) 1 October 22nd 09 10:40 PM
Auto file naming Jacquesvv Excel Discussion (Misc queries) 1 June 23rd 09 03:57 PM
Auto naming worksheets Kenny R Excel Discussion (Misc queries) 1 December 7th 06 10:38 PM
Auto naming Tabs in a Workbook Johnny Excel Discussion (Misc queries) 5 August 29th 06 05:42 PM
Naming Worksheets LIAMT Excel Worksheet Functions 1 August 21st 05 03:41 PM


All times are GMT +1. The time now is 03:40 AM.

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"