Results 1 to 5 of 5

Thread: Pivot table variable problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,888
    Location
    Not holding anything against anybody

    I did clean (OK, change) some macro a little to try and see what's going on and for my testing

    I think that the DateBefore has to be in US format, i.e. mm/dd/yyyy, regardless of regional setting. So give this a shot. You might need to experiment a little

    There were some things in the marco that I didn't see the reason for, but I tried to leave them alone

    Option Explicit
    
    Sub ula_sevk()
        ' PURPOSE: Delete all Pivot Tables in your Workbook
        ' SOURCE: www.TheSpreadsheetGuru.com
        Dim sht As Worksheet, shtData As Worksheet, shtPT As Worksheet
        Dim pvt As PivotTable
        Dim dateBefore As Date
        ' Loop Through Each Pivot Table In Currently Viewed Workbook
        For Each sht In ActiveWorkbook.Worksheets
            For Each pvt In sht.PivotTables
                pvt.TableRange2.Clear
            Next pvt
        Next sht  
        Set shtData = Worksheets("Sayfa1")
        With shtData
            .Select
            .Range("H1").FormulaR1C1 = "GÖNDEREN"
            .Range("J1").FormulaR1C1 = "TESLİM ALAN"
            .Range("H2").Select
        End With    
        On Error Resume Next
        Application.DisplayAlerts = False
        Worksheets("PT").Delete
        Application.DisplayAlerts = True
        On Error GoTo 0    
        Worksheets.Add
        Set shtPT = ActiveSheet
        shtPT.Name = "PT"    
        ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=shtData.Name & "!" & shtData.Cells(1, 1).CurrentRegion.Address, _
        Version:=7).CreatePivotTable TableDestination:=shtPT.Name & "!R3C1", TableName:="PivotTable1", DefaultVersion:=7    
        With ActiveSheet.PivotTables("PivotTable1")
            With .PivotCache
                .RefreshOnFileOpen = False
                .MissingItemsLimit = xlMissingItemsDefault
            End With        
            .ColumnGrand = False
            .HasAutoFormat = True
            .DisplayErrorString = False
            .DisplayNullString = True
            .EnableDrilldown = True
            .ErrorString = ""
            .MergeLabels = False
            .NullString = ""
            .PageFieldOrder = 2
            .PageFieldWrapCount = 0
            .PreserveFormatting = True
            .RowGrand = False
            .SaveData = True
            .PrintTitles = False
            .RepeatItemsOnEachPrintedPage = True
            .TotalsAnnotation = False
            .CompactRowIndent = 1
            .InGridDropZones = False
            .DisplayFieldCaptions = True
            .DisplayMemberPropertyTooltips = False
            .DisplayContextTooltips = True
            .ShowDrillIndicators = True
            .PrintDrillIndicators = False
            .AllowMultipleFilters = False
            .SortUsingCustomLists = True
            .FieldListSortAscending = False
            .ShowValuesRow = False
            .CalculatedMembersInFilters = False
            .RowAxisLayout xlCompactRow    
            .RepeatAllLabels xlRepeatLabels    
            .RowAxisLayout xlTabularRow    
            With .PivotFields("Malı teslim alan")
                .Orientation = xlRowField
                .Position = 1
                .Subtotals = Array(False, False, False, False, False, False, False, False, False, False, False, False)
            End With        
            With .PivotFields("TESLİM ALAN")
                .Orientation = xlRowField
                .Position = 2
                .Subtotals = Array(False, False, False, False, False, False, False, False, False, False, False, False)
            End With   
            With .PivotFields("Teslimat")
                .Orientation = xlRowField
                .Position = 3
                .Subtotals = Array(False, False, False, False, False, False, False, False, False, False, False, False)
            End With    
            With .PivotFields("Yaratma tarihi")
                .Orientation = xlRowField
                .Position = 4
                .Subtotals = Array(False, False, False, False, False, False, False, False, False, False, False, False)
            End With    
            With .PivotFields("GÖNDEREN")
                .Orientation = xlRowField
                .Position = 5
                .Subtotals = Array(False, False, False, False, False, False, False, False, False, False, False, False)
            End With        
            .PivotFields("Yaratma tarihi").AutoGroup    
            dateBefore = DateAdd("d", -7, Date)
            .PivotFields("Yaratma tarihi").PivotFilters.Add2 Type:=xlBefore, Value1:=Format(dateBefore, "mm/dd/yyyy")
        End With    
        With shtPT
            .Range("D4").Ungroup
            .Cells.EntireColumn.AutoFit
            .Range("D3").Select
        End With
    End Sub
    Attached Files Attached Files
    Last edited by Aussiebear; 04-16-2025 at 03:55 PM.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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