+ Reply to Thread
Results 1 to 6 of 6

Create New WB with copy of Sheets 1 & 2 when sheets count reaches 100

  1. #1
    Corey
    Guest

    Create New WB with copy of Sheets 1 & 2 when sheets count reaches 100

    What i want to do is create a New workBook, when the number of worksheets reaches 100.
    I have a button set up to create a new record(sheet) from a Template (Sheet1) in a workbook.
    To save over sizing and increasing the chances of a file crash, i want to have the WB, if the create a New Record Buton is clicked and there is already 99 Records(sheets) in the file, The make a Copy of the first 2 sheets(Opening Page & Template) and CREATE a NEW WORKBOOK with these in them.

    Currently i have this:

    Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 25/06/2006 by Corey
    '
    Set wb = Workbooks.Add
    ThisWorkbook.Sheets("Template").Copy Before:=wb.Sheets(1)
    For i = wb.Sheets.Count To 2 Step -1
    wb.Sheets(i).Delete
    Next i
    wb.Sheets(1).Name = "Template"

    '
    End Sub


    It will copy 1 Sheet only, But i need to adapt this to copy the first 2 sheets, AND to do so ONLY when the Number of SHEETS totals say 99.



    Any idea's, is it possible?

    Corey....








  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Corey,

    Sub Macro1()
    With ThisWorkbook
    If .Worksheets.Count < 99 Then Exit Sub
    .Worksheets(Array("Opening Page", "Template")).Copy
    End With
    End Sub

    Sincerely,
    Leith Ross

  3. #3
    Corey
    Guest

    Re: Create New WB with copy of Sheets 1 & 2 when sheets count reaches 100

    Leith,
    Cheers works perfectly thanks


    Corey....
    "Leith Ross" <[email protected]> wrote
    in message news:[email protected]...
    >
    > Hello Corey,
    >
    > Sub Macro1()
    > With ThisWorkbook
    > If .Worksheets.Count < 99 Then Exit Sub
    > Worksheets(Array("Opening Page", "Template")).Copy
    > End With
    > End Sub
    >
    > Sincerely,
    > Leith Ross
    >
    >
    > --
    > Leith Ross
    > ------------------------------------------------------------------------
    > Leith Ross's Profile:
    > http://www.excelforum.com/member.php...o&userid=18465
    > View this thread: http://www.excelforum.com/showthread...hreadid=555333
    >




  4. #4
    Corey
    Guest

    Re: Create New WB with copy of Sheets 1 & 2 when sheets count reaches 100

    Is it possible to ADAPT this code so that IF less than (<99) sheets are the
    case then MACRO2 runs,
    If there is 99 sheets then to RUN this Copy Code ?

    Sub Macro1()
    With ThisWorkbook
    If .Worksheets.Count < 99 Then Exit Sub ' Macro2 to run if LESS THAN 99
    instead of exit,
    BUT
    still need EXIT SUB, so creation of a new workbook copy
    does
    not go ahead when les than 99 sheets.
    Worksheets(Array("Enter - Exit Page", "Template")).Copy
    End With
    End Sub


    Think it is asimply step tried:

    With ThisWorkbook
    If .Worksheets.Count < 99 Then Macro2

    Worksheets(Array("Enter-Exit Page", "Template")).Copy
    End With
    End Sub

    But it ALSO creates a COPY, as it does not EXIT the SUB after running
    Macro2.


    Corey....



  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Corey,

    Here is the revised code...

    Sub Macro1()
    With ThisWorkbook
    If .Worksheets.Count < 99 Then
    Call Macro2
    Exit Sub
    End If
    If .Worksheets.Count = 99 Then
    .Worksheets(Array("Opening Page", "Template")).Copy
    End If
    End With
    End Sub

    Sincerely,
    Leith Ross

  6. #6
    Corey
    Guest

    Re: Create New WB with copy of Sheets 1 & 2 when sheets count reaches 100

    Thanks heaps Leith.

    Perfect....
    Just a Q though..
    Is it possible to add a step to save the old WorkBook Name as the current
    DATE instead, and to rename the NEWLY created WB as the OLD WB's name
    somehow ?


    Corey....




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1