jeffreyweir
Active Member
Howdy folks.
I wrote a post some time back at http://dailydoseofexcel.com/archives/2013/11/09/a-date-with-pivotitems highlighting a problem I had whereby if I tried to change the .visible status of a PivotItem that happenned to be a date - and that if the PivotField had a number format set to General rather than a date format - then I was getting the following error:
Run-time error ’1004′:
Unable to set the Visible property of the PivotItem class
But someone just commented at that thread that they don't have the same issue on either Excel 2010 or 2013. Whereas I find on my own machine that it works fine in Excel 2013 but not Excel 2010.
I’m wondering if it’s some kind of regional issue and version issue.
I'm looking for a few kind souls to run the following code on a blank workbook, and see what happens. It just sets up a pivot with two items in it, then tries to make both those items visible - first with the number format set to a date format, and then with the number format set to 'General'
I just need to know whether the code runs fine, or (if not) what line it throws an error on. I also need to know what version(s) of Excel you ran it on, and what international version of Excel you have.
Many thanks
Jeff
For me, in Excel 2013 this runs fine, but in Excel 2010 errors out where indicated in the comment.
Cheers
Jeff
I wrote a post some time back at http://dailydoseofexcel.com/archives/2013/11/09/a-date-with-pivotitems highlighting a problem I had whereby if I tried to change the .visible status of a PivotItem that happenned to be a date - and that if the PivotField had a number format set to General rather than a date format - then I was getting the following error:
Run-time error ’1004′:
Unable to set the Visible property of the PivotItem class
But someone just commented at that thread that they don't have the same issue on either Excel 2010 or 2013. Whereas I find on my own machine that it works fine in Excel 2013 but not Excel 2010.
I’m wondering if it’s some kind of regional issue and version issue.
I'm looking for a few kind souls to run the following code on a blank workbook, and see what happens. It just sets up a pivot with two items in it, then tries to make both those items visible - first with the number format set to a date format, and then with the number format set to 'General'
I just need to know whether the code runs fine, or (if not) what line it throws an error on. I also need to know what version(s) of Excel you ran it on, and what international version of Excel you have.
Many thanks
Jeff
Code:
Sub Test()
Dim pf As PivotField
Dim pc As PivotCache
Dim pt As PivotTable
Dim pi As PivotItem
Dim rng As Range
[A1].Value = "Data"
[A2].Value = "=TODAY()"
[A3].Value = "=VALUE(TODAY())"
Set rng = Cells(ActiveSheet.UsedRange.Row, ActiveSheet.UsedRange.Columns.Count + ActiveSheet.UsedRange.Column + 1)
Set pc = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=[A1].CurrentRegion)
Set pt = pc.CreatePivotTable(TableDestination:=rng)
Set pf = ActiveSheet.PivotTables(1).PivotFields(1)
pf.NumberFormat = "d/mm/yyyy"
For Each pi In pf.PivotItems
pi.Visible = True
Next pi
pf.NumberFormat = "General"
For Each pi In pf.PivotItems
pi.Visible = True 'Code errors out for me here using Excel 2010
Next pi
End Sub
For me, in Excel 2013 this runs fine, but in Excel 2010 errors out where indicated in the comment.
Cheers
Jeff