+ Reply to Thread
Results 1 to 6 of 6

Thread: How do I batch add sheets?

  1. #1
    Registered User
    Join Date
    11-20-2011
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    3

    How do I batch add sheets?

    I would like to add about 100 sheets to an Excel file, so first sheet would be WO #1, then WO #2......WO #100.

    Is there any way to do this as a batch operation?

  2. #2
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,316

    Re: How do I batch add sheets?

    I created this macro which you can assign to a button:
    Sub add_sheets()
    
    For i = 1 To 100
        Worksheets.Add(after:=Worksheets(Worksheets.Count)).Name = "WO #" & i
    Next
    
    Worksheets("Sheet1").Delete
    Worksheets("Sheet2").Delete
    Worksheets("Sheet3").Delete
    
    End Sub
    The macro creates 100 blank sheets and i did this in a blank workbook which had the default Sheet1, 2 and 3, which i delete at the end of the code. You can put a quote in front of these lines and it will quit the deleting.
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    11-20-2011
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: How do I batch add sheets?

    Im sorry im new at this. Where do I enter the code you provided, and how do I assign to a button?

    Many thanks!

  4. #4
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,316

    Re: How do I batch add sheets?

    In the excel file, click Alt+F11. This will take you to the VBE Editor. On the left hand side, you will see Microsoft Excel Objects. Right click on it and say Insert-> Module. This will open a blank page on the right hand side. Copy the code there and save. Come back to the excel sheet and go to Developer tab, under Controls, there will be Insert. Select the button type. Insert it on your sheet. You can name it right away. Then right click and say Assign Macro. You will see the name of the macro that i created in the list. Select it. Save the file. You are ready to go.
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  5. #5
    Registered User
    Join Date
    11-20-2011
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: How do I batch add sheets?

    Thanks! Now, if I want all these sheets to contain the same set of data, how would I do that? Basically, I want to copy whats in my first sheet and populate all 100 sheets with the same data.
    Last edited by ilans1; 11-20-2011 at 03:13 PM.

  6. #6
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,316

    Re: How do I batch add sheets?

    The code is simple - Very similar to the 1st -
    Sub add_sheets()
    
    For i = 1 To 100
       Worksheets("Sheet1").Copy after:=Worksheets(Worksheets.Count)
       ActiveSheet.Name = "WO #" & i
        
    Next
    
    End Sub
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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.2.0