View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.worksheet.functions
John[_22_] John[_22_] is offline
external usenet poster
 
Posts: 694
Default Excel Sheet tab names

Good Man, Dave
At least one person is trying to help.
Regards
John
"Dave Peterson" wrote in message
...
First, I find this kind of stuff very dangerous. Too many things can
contribute
to break the process. For instance, if you move a sheet, then it may get
renamed incorrectly.

But if you want, you could run a routine like this.

It assumes that the first sheet (leftmost) shouldn't be touched.
The second sheet (2nd from the left) contains the names in a1:Axx
And the 3rd (and the rest) should be named in that order.

Option Explicit
Sub testme()
Dim myRng As Range
Dim myCell As Range
Dim wCtr As Long
Dim HowManyNames As Long

With Sheets(2) 'second position!
Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
End With

HowManyNames = myRng.Cells.Count

If HowManyNames < ActiveWorkbook.Sheets.Count - 2 Then
MsgBox "the number of names doesn't match the number of sheets!"
Exit Sub
End If

wCtr = 3 'since we want to start with the 3rd sheet
For Each myCell In myRng.Cells
On Error Resume Next
Sheets(wCtr).Name = myCell.Value
If Err.Number < 0 Then
Err.Clear
MsgBox "Error renaming the sheets"
Exit Sub
End If
On Error GoTo 0
wCtr = wCtr + 1
Next myCell

End Sub

You'll type in the names and then run the macro. If the list changes, you'll
have to rerun the macro.



If you're new to macros:

Debra Dalgleish has some notes how to implement macros he
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)

Carl wrote:

I am making a program in excel for some time cards then workbook starts with
sheet one to change the date next sheet has the list of names with all the
info that needs to be put on the timesheet that lists all the names in
alphabetical order and the sheet that follow are the timecards i can get it
to put all the info itto the sheet but what i need to do is get the sheet
name tab to change to what the name from the list is so the tab names changes
as the list changes can someone help please.



--

Dave Peterson