+ Reply to Thread
Results 1 to 13 of 13

Create Multiple worksheet in a workbook

  1. #1
    Registered User
    Join Date
    01-16-2019
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    38

    Question Create Multiple worksheet in a workbook

    Hello,
    I'm able to create a multiple worksheets using following VBA code,

    Option Base 1

    Sub AddMultipleSheetswithNames()
    Worksheets.Add After:=Sheet1, Count:=4
    Dim p, q As Integer
    Dim Sheetname

    Sheetname = Array("A", "B", "C", "D", "E")
    p = Worksheets.Count
    For q = 1 To p
    With Worksheets(q)

    .Name = Sheetname(q)
    End With
    Next q

    End Sub

    It does create new worksheets with name A through E but it remove the sheet1 ( that was originally with the workbook). so what should I modify in above code to keep the sheet1 and then add new worksheets A through E?

    Any help would be appreciated.

    Thank you.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Create Multiple worksheet in a workbook

    Change 1 to 2 in the loop.


    PS When posting code can you please use CODE tags?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    01-16-2019
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    38

    Re: Create Multiple worksheet in a workbook

    Thank you for your quick reply. Per your suggestion I changed the for loop
    For q=2 to p
    Now it's keeping the sheet1 but it starts from B instead of A.
    Any further help?

    Thanks again..
    Last edited by dax007; 01-16-2019 at 03:53 PM.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Create Multiple worksheet in a workbook

    Oops, forgot you were using the loop variable in an array.

    Within the loop try using this.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-16-2019
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    38

    Re: Create Multiple worksheet in a workbook

    Thank you for your help. it worked as expected.

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: Create Multiple worksheet in a workbook

    Another option
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-16-2019
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    38

    Re: Create Multiple worksheet in a workbook

    Thank you for your help

  8. #8
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: Create Multiple worksheet in a workbook

    You're welcome & thanks for the feedback

  9. #9
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Create Multiple worksheet in a workbook

    @Fluff
    At this line it should be to 0
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  10. #10
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: Create Multiple worksheet in a workbook

    The OP is using Option Base 1, so it needs to be 1 not 0

  11. #11
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Create Multiple worksheet in a workbook

    Thanks a lot for the information. I didn't notice this line (Sorry for that mistake)

  12. #12
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: Create Multiple worksheet in a workbook

    No apology needed
    and thanks for the rep

  13. #13
    Registered User
    Join Date
    01-16-2019
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    38

    Re: Create Multiple worksheet in a workbook

    THANK YOU All for your help on this problem...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Create a new workbook from a template worksheet using information from main workbook.
    By nathandavies9 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-21-2017, 11:28 AM
  2. Create a worksheet from results of the whole workbook (multiple sheet filtering)
    By ralfaia in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2015, 03:07 PM
  3. How to create a window in a worksheet to extract a particular worksheet in a workbook
    By alfredsoh in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-22-2013, 07:39 AM
  4. Vba cmd1 create workbook cmd2 create worksheet depend upon combobox values
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-17-2013, 03:20 AM
  5. [SOLVED] Create single worksheet from multiple workbooks with 4 worksheets in each workbook
    By VKS in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-11-2013, 03:35 AM
  6. Replies: 4
    Last Post: 04-02-2013, 02:55 PM
  7. [SOLVED] How can I create multiple rows of worksheet tabs in a workbook?
    By kdzugan in forum Excel General
    Replies: 1
    Last Post: 03-08-2005, 12:06 PM

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