Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 385
Default Macro to name worksheet tabs using a cell within the worksheet?

For example, if I have 50 worksheets in a workbook and in each one, cell A1
names the item, is there a macro I can create to automatically name the tabs
with the name in A1?

TIA for any help
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Macro to name worksheet tabs using a cell within the worksheet?

Jennifer

If each sheet's A1 entry is unique and no invalid charaters, this will do the
job.

Sub wsname()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Name = ws.Cells(1, 1).Value
Next ws
End Sub

If a chance of any duplicates or invalid characters try this error-trapped
version from Ron de Bruin

Sub Sheetname_cell()
Dim sh As Worksheet
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Worksheets
On Error Resume Next
sh.Name = sh.Range("A1").Value
'next lines cover duplicate names
If Err.Number 0 Then
MsgBox "Change the name of : " & sh.Name & " manually"
Err.Clear
End If
On Error GoTo 0
Next
Application.ScreenUpdating = True
End Sub


Gord Dibben MS Excel MVP

On Tue, 18 Jul 2006 12:10:02 -0700, Jennifer
wrote:

For example, if I have 50 worksheets in a workbook and in each one, cell A1
names the item, is there a macro I can create to automatically name the tabs
with the name in A1?

TIA for any help


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 385
Default Macro to name worksheet tabs using a cell within the worksheet

Thank you very much! The second one worked for me. You've been a great help!

"Gord Dibben" wrote:

Jennifer

If each sheet's A1 entry is unique and no invalid charaters, this will do the
job.

Sub wsname()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Name = ws.Cells(1, 1).Value
Next ws
End Sub

If a chance of any duplicates or invalid characters try this error-trapped
version from Ron de Bruin

Sub Sheetname_cell()
Dim sh As Worksheet
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Worksheets
On Error Resume Next
sh.Name = sh.Range("A1").Value
'next lines cover duplicate names
If Err.Number 0 Then
MsgBox "Change the name of : " & sh.Name & " manually"
Err.Clear
End If
On Error GoTo 0
Next
Application.ScreenUpdating = True
End Sub


Gord Dibben MS Excel MVP

On Tue, 18 Jul 2006 12:10:02 -0700, Jennifer
wrote:

For example, if I have 50 worksheets in a workbook and in each one, cell A1
names the item, is there a macro I can create to automatically name the tabs
with the name in A1?

TIA for any help



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Macro to name worksheet tabs using a cell within the worksheet

Happy to assist.

Thanks for the feedback.


Gord


On Tue, 18 Jul 2006 13:10:02 -0700, Jennifer
wrote:

Thank you very much! The second one worked for me. You've been a great help!

"Gord Dibben" wrote:

Jennifer

If each sheet's A1 entry is unique and no invalid charaters, this will do the
job.

Sub wsname()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Name = ws.Cells(1, 1).Value
Next ws
End Sub

If a chance of any duplicates or invalid characters try this error-trapped
version from Ron de Bruin

Sub Sheetname_cell()
Dim sh As Worksheet
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Worksheets
On Error Resume Next
sh.Name = sh.Range("A1").Value
'next lines cover duplicate names
If Err.Number 0 Then
MsgBox "Change the name of : " & sh.Name & " manually"
Err.Clear
End If
On Error GoTo 0
Next
Application.ScreenUpdating = True
End Sub


Gord Dibben MS Excel MVP

On Tue, 18 Jul 2006 12:10:02 -0700, Jennifer
wrote:

For example, if I have 50 worksheets in a workbook and in each one, cell A1
names the item, is there a macro I can create to automatically name the tabs
with the name in A1?

TIA for any help




Gord Dibben MS Excel MVP
  #5   Report Post  
Junior Member
 
Posts: 1
Default

What if I just want ot perform the procedure for a range of sheets, lets say sheet1 to sheet24. How do I set the loop just for that range. Thnx.

Quote:
Originally Posted by Gord Dibben View Post
Jennifer

If each sheet's A1 entry is unique and no invalid charaters, this will do the
job.

Sub wsname()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Name = ws.Cells(1, 1).Value
Next ws
End Sub

If a chance of any duplicates or invalid characters try this error-trapped
version from Ron de Bruin

Sub Sheetname_cell()
Dim sh As Worksheet
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Worksheets
On Error Resume Next
sh.Name = sh.Range("A1").Value
'next lines cover duplicate names
If Err.Number 0 Then
MsgBox "Change the name of : " & sh.Name & " manually"
Err.Clear
End If
On Error GoTo 0
Next
Application.ScreenUpdating = True
End Sub


Gord Dibben MS Excel MVP

On Tue, 18 Jul 2006 12:10:02 -0700, Jennifer
wrote:

For example, if I have 50 worksheets in a workbook and in each one, cell A1
names the item, is there a macro I can create to automatically name the tabs
with the name in A1?

TIA for any help
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
How do I get ONLY new info from 1 Worksheet to another automatical Elaine Excel Worksheet Functions 6 July 13th 06 05:45 PM
Adding a row to worksheet does not update cell references in another. blausen Excel Worksheet Functions 5 February 25th 06 09:14 PM
macro help thephoenix12 Excel Discussion (Misc queries) 4 July 15th 05 05:57 PM
Macro to search for and display data in another worksheet Mark H Excel Worksheet Functions 0 June 14th 05 12:40 PM
Possible Lookup Table Karen Excel Worksheet Functions 5 June 8th 05 09:43 PM


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