ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error 1004 with PivotItems.Visible (https://www.excelbanter.com/excel-programming/345916-error-1004-pivotitems-visible.html)

Charlie Rowe

Error 1004 with PivotItems.Visible
 
I record this macro as I un-select one item and then select another item:
With ActiveSheet.PivotTables("PivotTable1").PivotFields ("Env")
.PivotItems("1").Visible = False
.PivotItems("42").Visible = True
End With
But when I then try to run (playback) the macro, I get an error 1004.
I still get the error if I change the order and put True first, then False.

What am I missing?

Thanks,
Charlie Rowe



Debra Dalgleish

Error 1004 with PivotItems.Visible
 
To prevent the error, set the Sort for the field to Manual. For example:

Dim intASO As Integer
With ActiveSheet.PivotTables("PivotTable2").PivotFields ("Employee")
intASO = .AutoSortOrder
.AutoSort xlManual, .SourceName
.PivotItems("1").Visible = False
.PivotItems("42").Visible = True
.AutoSort intASO, .SourceName
End With

Charlie Rowe wrote:
I record this macro as I un-select one item and then select another item:
With ActiveSheet.PivotTables("PivotTable1").PivotFields ("Env")
.PivotItems("1").Visible = False
.PivotItems("42").Visible = True
End With
But when I then try to run (playback) the macro, I get an error 1004.
I still get the error if I change the order and put True first, then False.

What am I missing?

Thanks,
Charlie Rowe




--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html


Charlie Rowe

Error 1004 with PivotItems.Visible
 
Debra,

WOW, thank you so much; I would have never figured that out.
How did you ever figure it out?

Charlie Rowe



"Debra Dalgleish" wrote:

To prevent the error, set the Sort for the field to Manual. For example:

Dim intASO As Integer
With ActiveSheet.PivotTables("PivotTable2").PivotFields ("Employee")
intASO = .AutoSortOrder
.AutoSort xlManual, .SourceName
.PivotItems("1").Visible = False
.PivotItems("42").Visible = True
.AutoSort intASO, .SourceName
End With

Charlie Rowe wrote:
I record this macro as I un-select one item and then select another item:
With ActiveSheet.PivotTables("PivotTable1").PivotFields ("Env")
.PivotItems("1").Visible = False
.PivotItems("42").Visible = True
End With
But when I then try to run (playback) the macro, I get an error 1004.
I still get the error if I change the order and put True first, then False.

What am I missing?

Thanks,
Charlie Rowe




--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html




All times are GMT +1. The time now is 02:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com