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
Bookmarks