VBA to break a spreadsheet into many within a zip file

vmackey

New Member
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.
 

JLGWhiz

Well-known Member
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?
 

vmackey

New Member
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.
 

JLGWhiz

Well-known Member
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.
 

vmackey

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

Some videos you may like

This Week's Hot Topics

  • Get External Data (long shot question!)
    This is likely a long shot but I am wondering if it is at all possible for Excel to somehow 'change' the contents of a URL that is being linked to...
  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • Cell Formatting
    Good Morning, I need to format a few different cells in the following manners: A1 has to always add a colon (:) after whatever is typed in by a...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • Workbook_Change stopped working !
    I am working on an app to speed up & automate processing of Credit Cards statements. After data is input from a CSV file, it is presented to the...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
Top