PC Review


Reply
Thread Tools Rate Thread

Create Named Worksheets

 
 
=?Utf-8?B?QWlyZml2ZQ==?=
Guest
Posts: n/a
 
      21st Sep 2007
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
 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      21st Sep 2007
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" <(E-Mail Removed)> wrote in message
news0E195DD-9FEC-4227-BB20-(E-Mail Removed)...
> 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



 
Reply With Quote
 
JW
Guest
Posts: n/a
 
      21st Sep 2007
Number of different ways to handle this depending on where you want
the sheets inserted into the sheet structure. The code below will
cycle through all of the cells in column A, starting from the bottom
up and running until row 2, and add new sheets to the beginning of the
workbook. This will keep the sheets in the same order as they appear
in column A.
Sub createSheets()
Dim mainSheet As Worksheet
Set mainSheet = ActiveSheet
With mainSheet
lRow = .Range("A65536").End(xlUp).Row
For i = lRow To 2 Step -1
Worksheets.Add(Before:=Sheets(1)).Name = .Cells(i, 1).Text
Next
End With
Set mainSheet = Nothing
End Sub
Airfive wrote:
> 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


 
Reply With Quote
 
=?Utf-8?B?QWlyZml2ZQ==?=
Guest
Posts: n/a
 
      26th Sep 2007
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" <(E-Mail Removed)> wrote in message
> news0E195DD-9FEC-4227-BB20-(E-Mail Removed)...
> > 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

>
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      26th Sep 2007
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" <(E-Mail Removed)> wrote in message
> > news0E195DD-9FEC-4227-BB20-(E-Mail Removed)...
> > > 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
 
Reply With Quote
 
=?Utf-8?B?QWlyZml2ZQ==?=
Guest
Posts: n/a
 
      27th Sep 2007
Dave,

Thank you very much for your help and explanation. Everything works as
expected now. I thought it had something to do with the "Text" formatting
but I have very limited experience with VBA code and was unable to fix it
myself.

Also, once again, I want to thank all of you who help out others on this
forum. I for one always appreciate the prompt help and replies to any
questions I have. Thank you all.

Ron

"Dave Peterson" wrote:

> 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" <(E-Mail Removed)> wrote in message
> > > news0E195DD-9FEC-4227-BB20-(E-Mail Removed)...
> > > > 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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How use info in Excel shared worksheets to create new worksheets =?Utf-8?B?ZGtj?= Microsoft Excel Worksheet Functions 0 28th Jun 2007 08:36 PM
How can I name worksheets in Excel according to named ranges? =?Utf-8?B?RG9taW5pcXVl?= Microsoft Excel Worksheet Functions 4 1st Sep 2006 09:03 AM
using named cells across worksheets =?Utf-8?B?TmljayBNYWxvbmV5?= Microsoft Excel Discussion 2 20th Mar 2005 03:13 PM
Named ranges across worksheets Dan Microsoft Excel Misc 1 22nd Aug 2003 03:24 PM
Named Range across several worksheets Ed Bitzer Microsoft Excel Misc 2 9th Aug 2003 08:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:06 AM.