Link Pivot Table Collapse/Expand to worksheet rows

haroblueman

New Member
Joined
Jun 13, 2016
Messages
1
Hello. First time post, long time user of this sites great ideas.

Problem Set: I have (1) Work Sheet that has (4) columns, (140) Rows. Columns: Item 1, Item 2, Item 3, Item 4. > Created a Pivot Table in another Work Sheet that has these columns in a hierarchy in column A. I would like to (via VBA) link the [+]/[-] buttons in the Pivot Table (Column Name: Item 1, Item 2, Item3) to the Rows in the Work Sheet. Therefore I can hide and show data to the outside of the pivot table in columns B and on to the right. I have managed to get it to work hard coding the locations of each cell that has a [+]/[-] button available, but this isn't dynamic and if my users update the Items list and add another row it will throw off the exact cell reference in the VBA.

Work so Far:

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)

With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Dim rCell As Range
Cells.EntireRow.Hidden = False
For Each rcell In Range("A7:A140")
If rCell.Select = True Then
rCell.EntireRow.Hidden = True
Else
rCell.EntireRow.Hidden = False
End If
Next rCell
Application.EnableEvents = True
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,557
Latest member
richa mishra

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