• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

PVT Blank Row height issue

Hi all,
I am trying to decrease the height of the blank rows between items on a Pivot Table. The attached works but when fields are expanded, some items that are not blank, are formatted as if they were. My assumption is because the rows were blank and the expansion of the field is not recognising that fact.

Is there a VBA function that would rerun the code whenever a field is expanded? At present code runs on a PVT refresh only.

Code:
Sub rowheight()
Application.ScreenUpdating = False
    Dim hgt As Variant
    Dim WorkRng As Range
    xTxt = ActiveWindow.RangeSelection.Address
    Set WorkRng = Range("$b$16:$b$500")
For Each H In WorkRng
        If H.Value = "" Then
            hgt = H.Value
            H.EntireRow.Select
            Selection.rowheight = 2
        End If
    Next H
End Sub



Any help, much appreciated.

Thanks,

-CL
 
There is an event which is triggered when expanding/collapsing:
Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
MsgBox "triggered"
End Sub
It's in the code module of the sheet that the pivot table is on. In addition, the Target is the pivot table, so you'll be able to use ranges derived from the pivot table itself. The following is a complete guess and probably won't work because it's dependent on the design and layout of the pivot table (as well as it trying to work on any pivot on the same sheet), but something along the lines of:
Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
For Each cll In Target.RowRange.Cells
  If cll = "" Then cll.RowHeight = 5 Else cll.RowHeight = 15
Next cll
End Sub
To get a better answer attach a workbook with a bit more detail about what you want and where.
 
Back
Top