View Single Post
  #14   Report Post  
Posted to microsoft.public.excel.programming
Gord Dibben[_2_] Gord Dibben[_2_] is offline
external usenet poster
 
Posts: 621
Default Changing name of worksheet based on data in cell of another worksheet

Brad

Just to experiment and get a feel for what Paul's code does..............

Open a NEW workbook.

Delete all but one sheet...............name that sheet "Master"

Copy these two macros to a module in that workbook.

Sub Add_Sheets()
For i = 18 To 1 Step -1
Worksheets.Add.Name = "Stud" & i
Next
End Sub

Sub ChangeTabNames()
Dim myNames As Range, mycell As Range
Dim Temp As String, i As Integer

Application.ScreenUpdating = False

Set myNames = Worksheets("Master").Range("B13:B30")
i = 1
For Each mycell In myNames
Temp = "Stud" & i
Worksheets(Temp).Name = mycell.Value
i = i + 1
Next mycell
End Sub

Save workbook.

Run Add_Sheets macro to get 18 new sheets named Stud1 to Stud18

Enter a list of names in Master sheet at B13:B30

Save workbook.

Run Paul's ChangeTabNames macro.

What occurs?

Do you get the name changes?

Do you now want this to fully automated as Cliff suggests?


Gord Dibben MS Excel MVP





On Thu, 21 Apr 2011 10:55:35 -0700 (PDT), "
wrote:

I moved the code into it's own module and saved the workbook.
I then ran the Macro and recieved a "run-time error '9' Subscript out
of range"
I hit the "Debug" option and the VBE had the following line of code
highlighted:

Worksheets(Temp).Name = mycell.Value

Is there something wrong? Again I appreciate all the help everyone
has put forth!

Brad