Results 1 to 5 of 5

Thread: Pivot table variable problem

  1. #1

    Pivot table variable problem

    Hello

    Is it possible to make the date part variable in the vba code below? I would like your help.

    ActiveSheet.PivotTables("PivotTable1").PivotFields("Yaratma tarihi"). _
    PivotFilters.Add2 Türü:=xlBefore, Değer1:="20.01.2025"
    sample file

    https://drive.google.com/file/d/13VItbEzEhqrXsnRkwhjk92WF0IuyR7nH/view?usp=sharing
    Last edited by Aussiebear; 01-28-2025 at 02:56 AM.

  2. #2
    Site Admin VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,495
    Location
    Welcome vbax van_65166. 2 quick points for you to consider. When posting sections of code, please wrap them with code tags by either highlighting the code and then clicking on the hash (#) icon, or click the hash icon and then insert the code between the tags. Secondly, we would appreciate it if you used the file attachment function by clicking on the Go Advanced link bottom right of your intending post, then Manage Attachments and follow the prompts from there.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Quote Originally Posted by aussiebear View Post
    vbax van_65166'ya hoş geldiniz. Dikkate almanız gereken 2 hızlı nokta. Kod bölümlerini gönderirken, lütfen kodu vurgulayıp ardından hash (#) simgesine tıklayarak veya hash simgesine tıklayıp ardından kodu etiketler arasına ekleyerek bunları kod etiketleriyle sarın. İkinci olarak, amaçladığınız gönderinin sağ alt köşesindeki gelişmiş'e git bağlantısına tıklayarak dosya eki işlevini kullanmanızdan ve ardından ekleri yönet'e tıklayıp oradan gelen istemleri takip etmenizden memnuniyet duyarız.

    hello, don't hold it against me, i will be more careful, good luckTEST KİTAP.xlsm

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,887
    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

  5. #5
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,800
    Location
    Be as you wish to seem

Posting Permissions

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