For next loop doesn't work with certain PivotFields

szakharov7723

Board Regular
Joined
Jun 22, 2018
Messages
85
Office Version
  1. 2019
Platform
  1. Windows
When I use this code
VBA Code:
Sub FormatTest1()
With ActiveSheet.PivotTables("PriceHistory").PivotFields("Description")
    For i = 1 To .PivotItems.Count - 1
    .PivotItems(.PivotItems(i).Name).DataRange.Select
    Next i
End With
End Sub
It selects single total field. And loops through each (item labels hidden)
1576684357833.png



But when I try to use this code , it doesn't work
1576684715166.png

However this one selects all fields resulting in error later.
VBA Code:
Sub FormatTest1()
With ActiveSheet.PivotTables("PriceHistory").PivotFields("Years")
    For i = 1 To .PivotItems.Count - 1
    .PivotItems(.PivotItems(i).Name).DataRange.Select
    Next i
End With
End Sub

1576685987330.png


How can I select all dates for each item field ?
 

Attachments

  • 1576684876644.png
    1576684876644.png
    46.4 KB · Views: 6
I think the only way around would be to add a column in your source data Called Months and have a formula there to calculate the month for each transaction. Then use Month in your PT instead of Date.
 
Upvote 0
I think the only way around would be to add a column in your source data Called Months and have a formula there to calculate the month for each transaction. Then use Month in your PT instead of Date.
I think it may work to some extent, I will try to play with this to change loop method for item field
 
Upvote 0

Forum statistics

Threads
1,226,795
Messages
6,193,047
Members
453,772
Latest member
aastupin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top