Unhide Row as Pivot Table Gets Updated

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Unhide Row as Pivot Table Gets Updated

Post by adam »

The following code unhide’s the hidden rows and refreshes the pivot tables with looping. How could I make the code to unhide the rows without looping and also refresh the pivot tables?

Code: Select all

Private Sub Worksheet_Activate()

  Dim pvt As PivotTable
  Dim rw As Long
  Application.ScreenUpdating = False
  For Each pvt In Me.PivotTables
    pvt.RefreshTable
  Next pvt
  Application.Calculation = xlCalculationManual
    For rw = 48 To 1360
        If Not Range("A" & rw) = "" Then
            Range("A" & rw).EntireRow.Hidden = False
        End If
    Next rw
Application.Calculation = xlCalculationAutomatic
ScrollArea = "A1:AG1380"
Application.ScreenUpdating = True
End Sub
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78620
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Unhide Row as Pivot Table Gets Updated

Post by HansV »

I don't think you can refresh the pivot tables without looping.
For the rows, you could try

Range("A48:A1360").SpecialCells(xlCellTypeConstants).EntireRow.Hidden = False
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Unhide Row as Pivot Table Gets Updated

Post by adam »

Hans, Do you meant the final code would be as follows?

Code: Select all

Private Sub Worksheet_Activate()
  Dim pvt As PivotTable
  Application.ScreenUpdating = False
  For Each pvt In Me.PivotTables
    pvt.RefreshTable
  Next pvt
  Range("A48:A1360").SpecialCells(xlCellTypeConstants).EntireRow.Hidden = False
ScrollArea = "A1:AG1380"
Application.ScreenUpdating = True
End Sub
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78620
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Unhide Row as Pivot Table Gets Updated

Post by HansV »

Why don't you try it?
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Unhide Row as Pivot Table Gets Updated

Post by adam »

I've tried it.Thanks for the help
Best Regards,
Adam

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Unhide Row as Pivot Table Gets Updated

Post by adam »

The workbook in Post 22494 works excellent with its embedded code. But In doing so; it does hide the column containing the "Grand Total".

How could I make the code to prevent this?
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78620
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Unhide Row as Pivot Table Gets Updated

Post by HansV »

The code contains two instances of the line

For c = 2 To m + 1

Change both to

For c = 2 To m - 1
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Unhide Row as Pivot Table Gets Updated

Post by adam »

Thanks for the help. That was really helpful.
Best Regards,
Adam

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Unhide Row as Pivot Table Gets Updated

Post by adam »

The "Grand Total" Column does not get changed with month selection. How could it be made to change according to month selections?
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78620
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Unhide Row as Pivot Table Gets Updated

Post by HansV »

You can't do that with the row totals of a pivot table - they sum all columns whether they are visible or not.

You'd have to turn off the row totals in the pivot tables, and provide your own formulas or code to calculate them.
Best wishes,
Hans