Creating multiple sheets with a macro

I have run into an issue where i want to be able to create multiple
"Resource Plans" sheet with a macro but to have them created as needed
so to speak. I am trying to create a
macro that can be used to see if a sheet called "Resource Plans"
exists.  The once it is verified then create an additional sheet called
"Resource Plans-1". Also,  I want to it to only
add a planned sheet each time you run the macro but each time to go up
one count numerically within the name of the sheet (i.e. Resource
Plans-1, Resource Plans-2, etc.) I would like to be able to do this for
up to six new sheets.

On each new Resource Plan sheet I want it to copy
the format and the area I define of either the original "Resource
Plans" sheet or of the
previously created  Resource Plans sheet, but this part I can probably
figure out myself.

I am not sure if the best way to do this is with if statments or case
arguments or something else.  I figure that for the macro to be run
once and create a sheet named
 I also know that the second time through it would have to check to see
if "Resource Plans" and "Resource Plans-1" sheets exist to know to add
the next sheet. I hope their is a way to do this in a macro. What I
have been trying to do is not working. I appreciate any help I can get.

Sincerely,
Kyle

Here is my current code in case it helps.  I am not sure if I can do it
this way or not.  Please let me know if I can do it this way and if so
what changes/additions shoudl I make to the code to make it work.

Sub NewResPlanSh()
'
'

    Dim WS As Worksheet

   For Each WS In Workbooks(1).Worksheets
   Select Case WS.Name
     Case Is = "Resource Plans"
       Worksheets("Resource Plans").Activate
    Range("A1:M26").Select
    Selection.Copy
    Sheets.Add After:=Sheets(Sheets.Count)
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
        False, Transpose:=False
    Range("J24").Select
    Columns("J:J").EntireColumn.AutoFit
    Columns("B:B").ColumnWidth = 23.57
    Columns("B:B").ColumnWidth = 17.86
    Columns("J:J").ColumnWidth = 12
     Range("B12:H20").Select
    Application.CutCopyMode = False
    Selection.ClearContents
    Range("C5:J9").Select
    Selection.ClearContents
    Columns("I:I").ColumnWidth = 12
    Columns("B:B").ColumnWidth = 21.57
    Range("D16").Select
    ActiveSheet.Name = "Resource Plans-1"
     Case Is = "Resource Plans-1"
       Worksheets("Resource Plans-1").Activate
    Range("A1:M26").Select
    Selection.Copy
    Sheets.Add After:=Sheets(Sheets.Count)
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
        False, Transpose:=False
    Range("J24").Select
    Columns("J:J").EntireColumn.AutoFit
    Columns("B:B").ColumnWidth = 23.57
    Columns("B:B").ColumnWidth = 17.86
    Columns("J:J").ColumnWidth = 12
     Range("B12:H20").Select
    Application.CutCopyMode = False
    Selection.ClearContents
    Range("C5:J9").Select
    Selection.ClearContents
    Columns("I:I").ColumnWidth = 12
    Columns("B:B").ColumnWidth = 21.57
    Range("D16").Select
    ActiveSheet.Name = "Resource Plans-2"
     Case Is = "Resource Plans-2"
       Worksheets("Resource Plans-2").Activate
    Range("A1:M26").Select
    Selection.Copy
    Sheets.Add After:=Sheets(Sheets.Count)
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
        False, Transpose:=False
    Range("J24").Select
    Columns("J:J").EntireColumn.AutoFit
    Columns("B:B").ColumnWidth = 23.57
    Columns("B:B").ColumnWidth = 17.86
    Columns("J:J").ColumnWidth = 12
     Range("B12:H20").Select
    Application.CutCopyMode = False
    Selection.ClearContents
    Range("C5:J9").Select
    Selection.ClearContents
    Columns("I:I").ColumnWidth = 12
    Columns("B:B").ColumnWidth = 21.57
    Range("D16").Select
    ActiveSheet.Name = "Resource Plans-3"
   End Select
 Next WS

End Sub

0
syrney170 (1)
1/11/2006 6:31:09 PM
excel 39879 articles. 2 followers. Follow

1 Replies
527 Views

Similar Articles

[PageSpeed] 9

Kyle,

This will help you with the sheet creation. To use it you would do something 
like this:

Sub Name3Sheets()
Dim lCounter as long
For lCounter = 1 to 3
    SafelyRenameSheet ActiveWorkbook.Sheets(lCounter), "ResourcePlans"
Next lCounter
End Sub

Sub SafelyRenameSheet(shToName As Worksheet, strName As String)
'renames a sheet either to strName or to strName with a suffix if the 
original exists

Dim lSuffix As Long
Dim shTest As Worksheet

On Error GoTo SafelyRenameSheet_Error
lSuffix = 0

With ActiveWorkbook

    On Error Resume Next
    Set shTest = .Sheets(strName)
    On Error GoTo SafelyRenameSheet_Error

    If shTest Is Nothing Then

        shToName.Name = strName
        On Error GoTo 0
        Exit Sub

    End If

    Do While Not shTest Is Nothing

        lSuffix = lSuffix + 1

        Set shTest = Nothing
        On Error Resume Next
        Set shTest = .Sheets(strName & CStr(lSuffix))
        On Error GoTo SafelyRenameSheet_Error

    Loop

    shToName.Name = strName & CStr(lSuffix)

End With

EndRoutine:
On Error GoTo 0
Exit Sub

SafelyRenameSheet_Error:
'Error handling code here
Resume EndRoutine
End Sub

-- 
Robin Hammond
www.enhanceddatasystems.com

"syrney170" <syrney170@gmail.com> wrote in message 
news:1137004269.546864.32470@g43g2000cwa.googlegroups.com...
>
> I have run into an issue where i want to be able to create multiple
> "Resource Plans" sheet with a macro but to have them created as needed
> so to speak. I am trying to create a
> macro that can be used to see if a sheet called "Resource Plans"
> exists.  The once it is verified then create an additional sheet called
> "Resource Plans-1". Also,  I want to it to only
> add a planned sheet each time you run the macro but each time to go up
> one count numerically within the name of the sheet (i.e. Resource
> Plans-1, Resource Plans-2, etc.) I would like to be able to do this for
> up to six new sheets.
>
> On each new Resource Plan sheet I want it to copy
> the format and the area I define of either the original "Resource
> Plans" sheet or of the
> previously created  Resource Plans sheet, but this part I can probably
> figure out myself.
>
> I am not sure if the best way to do this is with if statments or case
> arguments or something else.  I figure that for the macro to be run
> once and create a sheet named
> I also know that the second time through it would have to check to see
> if "Resource Plans" and "Resource Plans-1" sheets exist to know to add
> the next sheet. I hope their is a way to do this in a macro. What I
> have been trying to do is not working. I appreciate any help I can get.
>
> Sincerely,
> Kyle
>
> Here is my current code in case it helps.  I am not sure if I can do it
> this way or not.  Please let me know if I can do it this way and if so
> what changes/additions shoudl I make to the code to make it work.
>
> Sub NewResPlanSh()
> '
> '
>
>    Dim WS As Worksheet
>
>   For Each WS In Workbooks(1).Worksheets
>   Select Case WS.Name
>     Case Is = "Resource Plans"
>       Worksheets("Resource Plans").Activate
>    Range("A1:M26").Select
>    Selection.Copy
>    Sheets.Add After:=Sheets(Sheets.Count)
>    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
> SkipBlanks:= _
>        False, Transpose:=False
>    Range("J24").Select
>    Columns("J:J").EntireColumn.AutoFit
>    Columns("B:B").ColumnWidth = 23.57
>    Columns("B:B").ColumnWidth = 17.86
>    Columns("J:J").ColumnWidth = 12
>     Range("B12:H20").Select
>    Application.CutCopyMode = False
>    Selection.ClearContents
>    Range("C5:J9").Select
>    Selection.ClearContents
>    Columns("I:I").ColumnWidth = 12
>    Columns("B:B").ColumnWidth = 21.57
>    Range("D16").Select
>    ActiveSheet.Name = "Resource Plans-1"
>     Case Is = "Resource Plans-1"
>       Worksheets("Resource Plans-1").Activate
>    Range("A1:M26").Select
>    Selection.Copy
>    Sheets.Add After:=Sheets(Sheets.Count)
>    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
> SkipBlanks:= _
>        False, Transpose:=False
>    Range("J24").Select
>    Columns("J:J").EntireColumn.AutoFit
>    Columns("B:B").ColumnWidth = 23.57
>    Columns("B:B").ColumnWidth = 17.86
>    Columns("J:J").ColumnWidth = 12
>     Range("B12:H20").Select
>    Application.CutCopyMode = False
>    Selection.ClearContents
>    Range("C5:J9").Select
>    Selection.ClearContents
>    Columns("I:I").ColumnWidth = 12
>    Columns("B:B").ColumnWidth = 21.57
>    Range("D16").Select
>    ActiveSheet.Name = "Resource Plans-2"
>     Case Is = "Resource Plans-2"
>       Worksheets("Resource Plans-2").Activate
>    Range("A1:M26").Select
>    Selection.Copy
>    Sheets.Add After:=Sheets(Sheets.Count)
>    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
> SkipBlanks:= _
>        False, Transpose:=False
>    Range("J24").Select
>    Columns("J:J").EntireColumn.AutoFit
>    Columns("B:B").ColumnWidth = 23.57
>    Columns("B:B").ColumnWidth = 17.86
>    Columns("J:J").ColumnWidth = 12
>     Range("B12:H20").Select
>    Application.CutCopyMode = False
>    Selection.ClearContents
>    Range("C5:J9").Select
>    Selection.ClearContents
>    Columns("I:I").ColumnWidth = 12
>    Columns("B:B").ColumnWidth = 21.57
>    Range("D16").Select
>    ActiveSheet.Name = "Resource Plans-3"
>   End Select
> Next WS
>
> End Sub
> 


0
rjNOrhSPAM (52)
1/13/2006 1:05:05 AM
Reply:

Similar Artilces:

How to stop "Undo" across multiple spreadsheets
When I am working between multiple separate worksheets, Undo will work backwards across all of the worsheets that I have open. How do I get the Undo function to work only on the worksheet that I am currently on? ...

create a roster
How can you create a weekly roster in which functions can be assigned to more than 10 people. The roster should be updatable, so that when holidays and days off are marked on the weekly roster they will be taken account of it future rosters. ...

macro problem with Word 2001
Whenever I attach a Word 2001 document to an email and send it to someone using PC, the PC user's computer interprets the macros as a virus. How can I a) disable macros on Word or b) send it in a way that the PC will not interpret it as a virus? Thanks for any help Hi Unless you are intentionally making Word documents with Macros it is almost certain that you are indeed sending documents that have a virus. If your Word documents are supposed to have macros, then your audience needs to adjust the security settings on their computer in Word (Tools > Options > Security > Ma...

importing or creating reference footnotes
I am trying to import a word document into publisher and it has reference footnotes within the document. The reference footnotes are not coming into the publisher document with the reference footnotes. Correct, they will not up to Publisher 2003. In Publisher 2003 depending on which version of Word you are using if they will or not. -- "If you don't know where you are going, any road will take you there!" ...

Mailbox not created when AD account created
A couple of days ago I noticed that I created a user account but the 'Email Addresses' tab of the user properies did not list any email addresses. Subsequent new user accounts have all experienced the same. I researched the knowledge and tried the recommended solutions to either manaully start the recipient update service or rebuild te recipient update service. Neither recommendation has resulted in a mailbox being created for this particular user or any additional user that I have created since this error first showed up. I performed a Windows update last Thursday and so I bel...

Task Create - Status
I'm trying to make a simple task, when a user owner is assigned a task in CRM, it receives an email letting it know it has one. I have the following below, but it is not generating one when i assign one manually in the CRM. What to do? I've tried both the following: When task is created E-Mail to:[owner];Subject test As well as: When task is created if Task activity status = Open then E-Mail to:[owner];Subject test I've checked the mailserver many times over, and I can send emails manually from the CRM so you can rule that out Tested out ok on our end. Some ideas:...

Splitting one table into multiple tables/tabs
Hi I was wondering if anyone can help me split a table into multiple tables or tabs. If I have a table of 20 customers with various transactions over time all in one table. I'd like to know if it's possible to seperate the table into multiple tables based on the change in customer number and have them broken into multiple tabs without manually creating each tab and then cut and pasting. I really appreciate any help! Thanks! ...

Help Creating XmlNode / XmlAttribute Elegantly
I am creating a configuration class to read / write a standard configuration file. <?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="ConnectionString" value="server=(local);" /> </appSettings> </configuration> I am using a XmlDocument for my base implementation. I am looking to see if there is a better way to add a new node / attribute than using XmlDocument.InnerXml. I would consider this to be a hack but couldn't really see another way of doing this without definin...

Create external database
Hi all. I need to create an external database (file). On a site I found this code: ------------------------------------------------------ Function CreateLinkedExternalTable(strTargetDB As String, strProviderString As String, strSourceTbl As String, strLinkTblName As String) As String 'strTargetDB = Source Database Name 'strProviderString = Not used, currently hard coded 'strSourceTbl = Source Table name in the database we are linking too. 'strLinkTblName = Table name we would like to see in the Access Database. Dim catDB As ADOX.Catalog Dim tblLink As...

How to create pie chart with %
I have got a problem that I don't if excel could help me to calculate the % within a column and draw a pie chart. My case is I have a column containing a series of numbers. e.g. 1,4,8,1,3,9,11,2,4,5,6,.........etc I want to draw a pie chart that showing 1-3 , 4-6, 7-9, >9 with the corresponding % inside that column. Can anyone tell me how can I make it ? Ray - You need to calculate the frequencies in your data. Let's assume your data is in A1:A12. In B1:B3 enter these numbers, the upper limits on the groupings: 3 6 9 You can enter ">9" into B4 witho...

how do I copy a range to a new sheet
Now that I this group solved my problem of flagging dates of my club members as "expired", how would I automatically copy all of the members that are expired to a new worksheet so I can use this for a mail merge? I would need to check the condition of the expired column, YES or NO, then copy the yes's name and address columns only to a new page. TIA Why not just add that column and when you use mailmerge, just include the records with that flag set the way you need? If you really want to copy the rows, you could apply Data|Filter|Autofilter and filter to show just those mem...

Email address not created when a new user is created
All, This issue recently happened in my company. Upon creating a new user, the policy was set to create the smtp and X400 address automaticaly. Now when we create a user the smtp and x400 addresses are not created, and when attempting to setup the new user in outlook, the address cant be found. We are using exchange 2003 SP1 on Win2k3 servers. On Wed, 13 Jul 2005 06:49:07 -0700, "Bryan" <Bryan@discussions.microsoft.com> wrote: >All, >This issue recently happened in my company. Upon creating a new user, the >policy was set to create the smtp and X400 addres...

Macro to insert Hard Space (character 160)?
Hello, Is there a very simple macro out there that would let me insert character 160 (the hard space) into the current cell? I am looking for something like this because I want to be able to apply "accountant single" and "accountant double" underlining to a blank cell, and Excel seems to demand that some text be IN the cell before it will underline it. The hard space works perfectly, but it would be nice to be able to automate it. Many thanks for any advice, Edward Mendelson Sub HardSpace() ActiveCell.Value = ActiveCell.Value & Chr(160) End Sub Jerry Edward...

Exchange 2010 MRM, no log files being created
I'm hoping someone can help me with this issue....it has been driving me crazy for days. I have enabled MRM logging on our exchange server, and I can see that some of the policies are working when I run start-managedfolderassistant. We have a retention policy tag on the deleteditems folder, and this does work. The problem is I am not getting any files in the MRM log directory. C:\Program Files\Microsoft\Exchange Server\V14\Logging\Managed Folder Assistant Events 9021 and 9022 are logged in the Application log, but where are the files? Below is the output of my mai...

when form created
I have a form which was created by someone else (not a form template) which is like a questionnaire with empty boxes to be completed. When the boxes are typed in all the margins move to accommodate the words being typed. Is there a way to fix/lock the original form and then just fill in the blank boxes? I suspect this is set up as a table with auto resizing enabled. Displaying table gridlines (Table | Show Gridlines) will help you see what you're dealing with. Then select the table, go to the Table tab of Table Properties, click Options, and clear the check box for "A...

how many lines per sheet in excel 2003
ave they increased the number of lines in excel 2003 or is it still 65536 Still, ever heard of 'categorizing'? Danny On Sun, 17 Jul 2005 16:04:01 -0700, Des53 <Des53@discussions.microsoft.com> wrote: > ave they increased the number of lines in excel 2003 or is it still 65536 -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ Hi Des, Row and column specifications are unchanged in xl2003 (65536 x 256). I have heard no suggestion that these are likely to change any time soon --- Regards, Norman "Des53" <Des53@discus...

Creating a Brochure
How do you create a 3-column brochure from scratch for Publisher 2002? I can only find the directions for the 2003 version. Quick help would be appreciated, project is due Monday. Create a three-panel or four-panel folded publication http://office.microsoft.com/en-us/assistance/HP011646681033.aspx Scroll down to the section that says "Build a three-panel or four-panel publications from scratch." -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Derek" <Derek@discussions.microsoft.com> wrote in message news...

Enabling Macro But Hiding Sheets
I have created a simple macro that basically when a button is clicked i takes you to a certain page in the workbook. Is it possible to hide this page for different users. But when a use with the correct password comes he can click the button and he will b taken to the hidden page. Is it posible to do something like this along those line -- Message posted from http://www.ExcelForum.com It's possible, and if you search the archives: http://google.com/advanced_group_search?q=group:*excel* you'll find many ways to do this. You should know, however, that none of the methods will ...

How to create Access macro shortcut
I'm still using Access 97 and saw something the other day that I would like to use that was in Access 2000. In an Access 2000 database, there was a .mam file in a directory that launched the Access 2000 program and ran a macro. How do you set this up? Can it be done in Access 97? If so, how? Hi. > How do you set this up? Select the macro in the Database Window and right click with your mouse, then select "Create Shortcut..." in the pop-up menu. Follow the prompts for where to place the shortcut and what to name it. The default is: <PathToDeskTopDir>\Shortcut ...

Users mailboxes not created when user created
I have a problem that recently just started happening on my exchange 2003 server. When i create a new user account and create the mailbox for exchange, once im done, the mailbox isnt created, adn if you go into the properties of the user account adn go to the exchange email address tab, there isnt an smtp or an x.400 address listed. I am having to manually create and add these, adn then go delete the exchange mailbox and recreate it. This is really annoying and would love to know if anyone has any ideas of how to fix it. Thanks Jason In news:9F836A43-98BF-435A-AA43-AFF10124BE3F@micro...

moving records from one sheet to other
Hi I have 1400 records in one sheet. i want is as a read only sheet. now i need a selection cell and a push button for each and every record. when the shared users select their name from the selection cell then click one of the push button then the appropriate record should move to the sheet which is for that particular user. i have 15 sheets for every individual.can u plz help me out. i'm very new to excel. knight Hopefully this will help you some. This code would be attached to a single button - what it does is see if the currently active cell is in the proper column (with na...

Multiple tables output to multiple sheets in single excel workbook
Hi all, Been a while since I've done any access dev, and I can't for the life of me remember how to do this. I have 3 tables I need to export to Excel, preferably in one workbook as separate sheets. Using OutputTo simply overwrite the file, and I seem to recall using transfertext to accomplish this, but it says the file is read-only after the first table is output. Do I need to create an export spec? If so, how do I go about this? Or is this simply not going to happen without using the Office library reference and all that jazz? TIA, SusanV Thanks Tom - I'll give it a ...

Selecting column D automatically when you leave the sheet
I have an xl2003 workbook with several worksheets. Some sheet contain tables, or instructions, etc. Most of the sheets are identical templates i create as i need them. On these templates sheets, which are named 1, 2, 3, etc., I would like to, when i leave the sheet, I would like for the activecell.column to be column D. That is, when i leave the sheet, column D of the current row is selected. I have tried several ways to accomploish this, with no success. Thanks, Tosno You can use an Event macro to Select column D in the worksheet when the sheet gets deactivated: Private Sub Worksheet_Deac...

Old emails not displayed (Multiple PC's using same inbox)
I have 2 machines running XP and Outlook 2000. Both mahcines are setup to using the same Exchange Server email account. When i open outlook in one machine all mail are visable is the inbox, and new mail is received correctly. But if i opne Outlook on the second machine my inbox is empty. Any new mails will appear quickly then disappear. I cannot get the second machine to display old emails. If I leave the first machine off, all new mail will stay in the second machines inbox, but if I open outlook on the second machine all mail disappears and is shown in the first machines inbox. A...

CRM should let me create custom fields in batch
Hi, With MS CRM v3.0, when we have a group of fields to create, it would be faster to be able to enter the list and then submit the list for processing. Thank you. Felix. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolutions/C...