Results 1 to 15 of 15

Change Pivot Items via VBA does not work

Threaded View

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Change Pivot Items via VBA does not work

    Hi Guys,

    i have Source data with dates from 01.01.2020 until 30.12.2020.

    From this i created pivot table and what want to do is to change all Pivot Items names to corresponding month.

    Using this code:

    Option Explicit
    
    Sub test()
    
    Dim pt As PivotTable
    
    With Sheet2
    
    Set pt = .PivotTables(1)
    
    Dim pi As PivotItem
    
    With pt
      For Each pi In .PivotFields("Dates").PivotItems
        
        Dim monthNaming As String
        Dim MonthFormat As String
        On Error Resume Next
        
            MonthFormat = Format(pi.Name, "yyyy-dd-mm")
            monthNaming = StrConv(MonthName(CLng(Month(CDate(MonthFormat)))), vbProperCase)
            If Err.Number = 0 Then
                pi.Name = monthNaming
            End If
        On Error GoTo 0
        
      Next pi
    End With
      
    End With
    
    End Sub
    and this is working only for first row!
    Why? Can anybody help?
    Very strange.

    Best,
    Jacek
    Attached Images Attached Images
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Pivot charts no longer work correctly at change of year
    By SJMaye in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 01-15-2016, 06:54 AM
  2. Filter pivot items using pivot items from another table
    By DKolev in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-16-2014, 08:49 PM
  3. Listbox, Need to change number of items in List (not the items)
    By Kalithro in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-14-2013, 09:23 PM
  4. [SOLVED] retrieve child items from visible pivot items.
    By MarMo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2013, 10:24 AM
  5. Replies: 1
    Last Post: 09-03-2012, 10:03 PM
  6. [SOLVED] Macro has to run twice to change correct pivot items
    By fratello in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-28-2012, 10:58 PM
  7. Change Pivot table Filter Based on Cell Value *Multiple Filter items* Possible?
    By Flydd in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-27-2012, 06:57 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1