View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Create Named Worksheets

You deleted "Option Explicit"!!

If you hadn't deleted that line, you would have been yelled at about this line:
ActiveSheet.Name = Format(myCell.Value, general)

General looks like it should be a variable and since it isn't declared, it'll
cause an error.

But even if you had used:

ActiveSheet.Name = Format(myCell.Value, general)

It' wouldn't have worked. VBA's Format and Excel's =Text() aren't
interchangeable.

But if those values on that List worksheet are really text values, then you
could use:
ActiveSheet.Name = myCell.Value
or
ActiveSheet.Name = myCell.Text

If they're really dates, you could use:
ActiveSheet.Name = myCell.Text 'if they're formatted nice
or
ActiveSheet.Name = Format(myCell.Value, "mmm yy")
(if Jan 07 represent January 2007?)

=======
If none of this helps, you may want to be more specific about what goes wrong.

Airfive wrote:

Hi Bob,

My apologizies for the late response. I caught a dang bad bug and got laid
up in the hospital for a bit. Below is the code I am using. I definetely
need to have each worksheet created using a template. Any help would be
greatly appreciated. Thanks.

Ron

Sub CreateNameSheets()
' by Dave Peterson
' (slightly revised by Max to format sheetnames <g)
' List sheetnames required in col A in a sheet: List
' Sub will copy sheets based on the sheet named as: Template
' and name the sheets accordingly

Dim TemplateWks As Worksheet
Dim ListWks As Worksheet
Dim ListRng As Range
Dim myCell As Range

Set TemplateWks = Worksheets("Template")
Set ListWks = Worksheets("list")
With ListWks
Set ListRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
End With

For Each myCell In ListRng.Cells
TemplateWks.Copy After:=Worksheets(Worksheets.Count)
On Error Resume Next
ActiveSheet.Name = Format(myCell.Value, general)
If Err.Number < 0 Then
MsgBox "Please fix: " & ActiveSheet.Name
Err.Clear
End If
On Error GoTo 0
Next myCell
End Sub

"Bob Phillips" wrote:

It might hep to post the code that you are using.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Airfive" wrote in message
...
Hello all,

I have read some posts regarding creating named worksheets but I am unable
to get it to work properly for me. I am using the macro from Dave
Peterson.
My "List" contains the following in column A......JAN 07, FEB 07, MAR 07
etc.
formatted in a text format. I want the macro to create and name the
worksheets as listed above but it won't work. I'm sure I'm doing
something
dumb.....lol......can someone help? Thanks.

Ron





--

Dave Peterson