Results 1 to 6 of 6

Thread: VBA to break a spreadsheet into many within a zip file

  1. #1
    New Member
    Join Date
    Jun 2019
    Location
    New York
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default VBA to break a spreadsheet into many within a zip file

    Hello. I am new to forum, a novice in excel and learning VBA. I have a request from my boss to see if I could develop a button that will break up a single spreadsheet "billing" file into multiple spreadsheets to upload into our billing software. The specs would include:

    1. A new spreadsheet will be created whenever a "client" name or value changes in column A.
    2. Ideally the spreadsheets will be combined in a zip file, but this is not required.
    3. Ideally the macro would be assigned to a "button" but also not required
    4. When exported, the content would be void of formulas and duplicated as values only.
    5. The header from the original spreadsheet would need to be transferred into all new spreadsheets.

    Some details on the file:
    1. There are multiple tabs (11 in total)
    2. The tab needed for export has data filling 35 columns, but I only want to export up to the 29th column.
    3. Each month's data would be approximately 3200-3500 rows
    4. there are approximately 195 "clients" meaning the macro would need to create 195 spreadsheets.

  2. #2
    Board Regular
    Join Date
    Feb 2012
    Location
    Florida, USA
    Posts
    10,925
    Post Thanks / Like
    Mentioned
    18 Post(s)
    Tagged
    2 Thread(s)

    Default Re: VBA to break a spreadsheet into many within a zip file

    2. The tab needed for export has data filling 35 columns, but I only want to export up to the 29th column.
    If there is only on Sheet out of 11 that needs to be worked, if so, what is the sheet name?
    Will the workbook containing the source data be open at runtime? If not and the directory path is different than the workbook hosting the code, then provide the path for opening the workbook.
    Will the code be hosted by a workbook other than the source workbook?
    Using Windows 10, Excel 2013.
    Any code provided by me should be tested on a copy or a mock-up of your file before applying it to your original file. Some actions generated by VBA code cannot be reversed with the undo facility in Excel. To open the VB editor, press Alt + F11. To run code from the Excel window, press Alt + F8. Please do not attempt to learn everything about VBA in one thread, especially from me. See this link for attaching images: Attachments

  3. #3
    New Member
    Join Date
    Jun 2019
    Location
    New York
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA to break a spreadsheet into many within a zip file

    Hello, thank you for responding and apologies for the delayed response. Answers to your questions below:

    1. The sheet is named "Template Creation"

    2. Yes, the workbook containing the source data will be open at runtime

    3. No, the code will not be hosted by a workbook other than the source workbook.

  4. #4
    Board Regular
    Join Date
    Feb 2012
    Location
    Florida, USA
    Posts
    10,925
    Post Thanks / Like
    Mentioned
    18 Post(s)
    Tagged
    2 Thread(s)

    Default Re: VBA to break a spreadsheet into many within a zip file

    This assumes that the headers are in row 1 and data begins in row 2 of sheet 'Template Creation'.
    Code:
    Sub t()
    Dim lr As Long, sh As Worksheet, c As Range, wb As Workbook
    Application.Calculation = xlCalulationManual
    Set sh = Sheets("Template Creation")
    lr = sh.Cells.Find("*", , xlFormulas, xlPart, xlByRows, xlPrevious).Row
        With sh
            .Range("A1:A" & lr).AdvancedFilter xlFilterCopy, , .Range("B" & lr + 2), True
            For Each c In Range("B" & lr + 2).CurrentRegion.Offset(1)
                If c <> "" Then
                    .UsedRange.AutoFilter 1, c.Value
                    Set wb = Workbooks.Add
                   .Range("A1:AC" & lr).SpecialCells(xlCellTypeVisible).Copy
                    wb.Sheets(1).Range("A1").PasteSpecial xlPasteValues
                    wb.SaveAs ThisWorkbook.Path & "\" & c.Value & ".xlsx"
                    wb.Close False
                    .AutoFilterMode = False
                End If
            Next
            .Range("B" & lr + 2).CurrentRegion.ClearContents
        End With
    Application.Calculation = xlCalculationAutomatic
    End Sub
    This should take about three to five minutes to do 195 clients.
    Using Windows 10, Excel 2013.
    Any code provided by me should be tested on a copy or a mock-up of your file before applying it to your original file. Some actions generated by VBA code cannot be reversed with the undo facility in Excel. To open the VB editor, press Alt + F11. To run code from the Excel window, press Alt + F8. Please do not attempt to learn everything about VBA in one thread, especially from me. See this link for attaching images: Attachments

  5. #5
    New Member
    Join Date
    Jun 2019
    Location
    New York
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA to break a spreadsheet into many within a zip file

    Wow!!! This works fantastically! Thank you very much, you're very talented!!

  6. #6
    Board Regular
    Join Date
    Feb 2012
    Location
    Florida, USA
    Posts
    10,925
    Post Thanks / Like
    Mentioned
    18 Post(s)
    Tagged
    2 Thread(s)

    Default Re: VBA to break a spreadsheet into many within a zip file

    Happy to help,
    regards, JLG
    Using Windows 10, Excel 2013.
    Any code provided by me should be tested on a copy or a mock-up of your file before applying it to your original file. Some actions generated by VBA code cannot be reversed with the undo facility in Excel. To open the VB editor, press Alt + F11. To run code from the Excel window, press Alt + F8. Please do not attempt to learn everything about VBA in one thread, especially from me. See this link for attaching images: Attachments

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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