+ Reply to Thread
Results 1 to 9 of 9

Macro to Add Worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    05-07-2009
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    59

    Macro to Add Worksheet

    I'm looking for a macro that will insert/add a new worksheet, and then move that newly created worksheet to the end of the workbook. Sounds simple but I can't figure out how to do it.


    TIA!!
    Last edited by papaexcel; 05-20-2009 at 11:27 AM.

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,454

    Re: Macro to Add Worksheet

    Sub AddSheetAndMoveToEnd()
    Sheets.Add
    ActiveSheet.Move after:=Worksheets(Worksheets.Count)
    End Sub
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Registered User
    Join Date
    05-07-2009
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Macro to Add Worksheet

    Perfect! Thanks!

  4. #4
    Registered User
    Join Date
    05-07-2009
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Macro to Add Worksheet

    One other request...I also want a macro that will delete all existing worksheets in a workbook (sometimes as many as 30 worksheets) except for Sheet1 and Sheet2.

    Again, TIA!!

  5. #5
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,454

    Re: Macro to Add Worksheet

    Sub DeleteAllSheets()
    'Deletes all but 1st two sheets
    Application.DisplayAlerts = False
    For lp = Worksheets.Count To 3 Step -1
    Sheets(lp).Delete
    Next
    Application.DisplayAlerts = True
    End Sub

  6. #6
    Registered User
    Join Date
    05-07-2009
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Macro to Add Worksheet

    thanks, works great.

    I found out the following works equally as well...

     Dim ws As Worksheet
        Application.DisplayAlerts = False
        For Each ws In Worksheets
        If ws.Name <> "Sheet1" And ws.Name <> "Sheet2" Then ws.Delete
        Next
        Application.DisplayAlerts = True

+ 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