Results 1 to 18 of 18

Thread: Split Workwook and save

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #18
    Administrator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,315
    Location
    Below is the code that was exactly the same but i removed the need to use version 2302:
    Sub test()
        Dim x As Integer
        Dim wb As Workbook
        Dim rCell As Range
        Dim c As New Collection
        Dim col As Variant
        
        On Error Resume Next
        For Each rCell In Tabelle1.ListObjects("Tabelle1").ListColumns("Team").DataBodyRange.Cells
            c.Add rCell.Value, CStr(rCell.Value)
        Next rCell
        On Error GoTo 0
        
        For Each col In c
            Sheets(Array("Data", "Pivot", "Dashboard")).Copy
            Set wb = ActiveWorkbook
            With ActiveSheet.ListObjects("Tabelle1")
                .Range.AutoFilter Field:=1, Criteria1:="<>" & col, Operator:=xlAnd
                Application.DisplayAlerts = False
                .DataBodyRange.SpecialCells(xlVisible).Delete
                Application.DisplayAlerts = True
                .Range.AutoFilter Field:=1
            End With
            Sheets("Pivot").PivotTables("PivotTable1").ChangePivotCache ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="Tabelle1", Version:=8)
            Sheets("Pivot").PivotTables("PivotTable2").ChangePivotCache ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="Tabelle1", Version:=8)
            Sheets("Dashboard").Range("C4") = col
            wb.SaveAs Filename:=ThisWorkbook.Path & "\" & col & ".xlsx", FileFormat:=51, Password:=Cells(2, 2)
            wb.Close False
        Next col
    End Sub
    Last edited by georgiboy; 03-24-2023 at 02:00 AM.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2408, Build 17928.20080

Posting Permissions

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