+ Reply to Thread
Results 1 to 7 of 7

Create multiple workbooks with multiple sheets from a list

Hybrid View

Angrypirate Create multiple workbooks... 01-20-2014, 09:49 AM
venkatpvc Re: Create multiple workbooks... 01-20-2014, 10:26 AM
Angrypirate Re: Create multiple workbooks... 01-20-2014, 11:07 AM
venkatpvc Re: Create multiple workbooks... 01-20-2014, 12:18 PM
Angrypirate Re: Create multiple workbooks... 01-20-2014, 12:48 PM
venkatpvc Re: Create multiple workbooks... 01-20-2014, 01:08 PM
Angrypirate Re: Create multiple workbooks... 01-20-2014, 01:54 PM
  1. #1
    Registered User
    Join Date
    08-16-2013
    Location
    Fort Wayne
    MS-Off Ver
    Excel 2007
    Posts
    4

    Create multiple workbooks with multiple sheets from a list

    Hello,

    I am looking for a way to create multiple workbooks(starting in column B2) and for each workbook a list of sheets(starting in column C2)

    Example:

    1 Workbook Sheet
    2 Fruit apple
    3 Fruit oranges
    4 Fruit bananas
    5 Vegetable carrot
    6 Vegetable spinach


    Any help or direction is appreciated. Thank you

  2. #2
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: Create multiple workbooks with multiple sheets from a list

    if i understand you correctly,
    Sub myTest()
        Dim i As Integer, n As Integer
        Dim wsht As Worksheet
        Dim wbk As Workbook
        Dim bottomB As Long
        Dim bottomC As Long
        Dim fpath As String
        fpath = "C:\Users\pad71381\Documents\newPhots" ' change the path name
        If Not Right(fpath, 1) = "\" Then fpath = fpath & "\"
        Set wsht = Worksheets("somesheet") 'change the sheet name
        bottomB = wsht.Cells(Rows.Count, 2).End(xlUp).Row
        bottomC = wsht.Cells(Rows.Count, 3).End(xlUp).Row
        For i = 2 To bottomB
            If wsht.Cells(i, 2) > "" Then
                Set wbk = Workbooks.Add
                For n = 2 To bottomC
                    With wbk
                        .Sheets.Add(after:=Sheets(Sheets.Count)).Name = wsht.Cells(n, 3)
                    End With
                Next n
            End If
            wbk.SaveAs fpath & wsht.Cells(i, 2)
            wbk.Close
        Next i
    End Sub
    Give Feedback and Click(*)

  3. #3
    Registered User
    Join Date
    08-16-2013
    Location
    Fort Wayne
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Create multiple workbooks with multiple sheets from a list

    Thank you for you reply.

    I had an overflow error on line 'For i = 2 To bottomB' so I changed 'Dim i As Long, n As Long' and when I ran, I discovered I have sheet names that are longer than 31 chars. I will sort through my table and attempt to edit those accordingly and retest.

    Another concern I have is whether or not this will check for already created workbooks. What will happen if I run this on the same sheet twice?

  4. #4
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: Create multiple workbooks with multiple sheets from a list

    try this code and tell me this is waht you asked for?
    Option Explicit
    
    Sub myTest()
        Dim i As Integer, n As Integer
        Dim wSht As Worksheet
        Dim Wbk As Workbook
        Dim bottomB As Long
        Dim bottomC As Long
        Dim fPath As String
        Dim myObj As Object
        fPath = "C:\Users\pad71381\Documents\newPhots" ' change the path name
        If Not Right(fPath, 1) = "\" Then fPath = fPath & "\"
        Set wSht = ThisWorkbook.Worksheets("Sheet1") 'change the sheet name
        bottomB = wSht.Cells(Rows.Count, 2).End(xlUp).Row
        bottomC = wSht.Cells(Rows.Count, 3).End(xlUp).Row
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
        For i = 2 To bottomB
            If wSht.Cells(i, 2) <> "" Then
                Set Wbk = Workbooks.Add
                For n = 2 To bottomC
                    With Wbk
                        If wSht.Cells(n, 3) <> "" Then
                            If Not Evaluate("ISREF('" & wSht.Cells(n, 3) & "'!A1)") Then
                                .Sheets.Add(after:=Sheets(Sheets.Count)).Name = wSht.Cells(n, 3)
                            End If
                        End If
                    End With
                Next n
            End If
            Set myObj = CreateObject("Scripting.FileSystemObject")
            If myObj.FileExists(fPath & wSht.Cells(i, 2) & ".xlsx") = True Then
                If MsgBox("There is Workbook already open" & vbCrLf & "Do you want Replace Exists one Click Yes" & _
                    vbCrLf & "To Abort Action Click No", vbYesNo) = vbYes Then
                    Wbk.SaveAs fPath & wSht.Cells(i, 2)
                    Wbk.Close
                Else
                    Wbk.Close False
                    Exit For
                End If
            Else
                Wbk.SaveAs fPath & wSht.Cells(i, 2)
                Wbk.Close
            End If
        Next i
        Application.ScreenUpdating = True
        Application.DisplayAlerts = True
        Set myObj = Nothing
    End Sub

  5. #5
    Registered User
    Join Date
    08-16-2013
    Location
    Fort Wayne
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Create multiple workbooks with multiple sheets from a list

    This code seems to add all of the sheets to 1 workbook.
    Also, I got the same overflow error for i and n, so I changed i and n to 'As Long' in order to step through.

    To elaborate, when done I will should have several workbooks with a varied amount of sheets for each.

  6. #6
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: Create multiple workbooks with multiple sheets from a list

    ok i think i understand you wrongly, can you post sample workbook with sample data with explanation.

  7. #7
    Registered User
    Join Date
    08-16-2013
    Location
    Fort Wayne
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Create multiple workbooks with multiple sheets from a list

    sampledata.xlsx

    Note: This is not the exact data, but the structure is the same

    I want to create several workbooks with names listed starting in B2, and in each workbook have the list of sheets in starting in C2.

    In this example, a workbook with manufacturer will have sheets for each model listed accordingly.
    Does this help?

    Edit: I realize the vagueness in my original question. To help clarify further in the sampledata Workbook named AAA will have sheets 110-133, BBB has sheets 201-226, CCC has 300-306, DDD has 444-485
    Last edited by Angrypirate; 01-20-2014 at 02:11 PM. Reason: clarification

+ 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. Create a dynamic list from multiple sheets
    By shbiskup in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-28-2022, 04:04 AM
  2. [SOLVED] Create master list from multiple sheets in the same format
    By malmandras in forum Excel General
    Replies: 1
    Last Post: 05-09-2013, 01:59 PM
  3. Replies: 1
    Last Post: 02-04-2013, 04:47 PM
  4. [SOLVED] VBA to create a list from multiple sheets
    By Jerums in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-27-2012, 03:23 PM
  5. create list from data on multiple sheets
    By bonsai79 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-20-2009, 08:46 AM

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