Hide rows in pivot table wehere the values are "empty" (VBA)

dkoek

New Member
Joined
Mar 11, 2016
Messages
4
Hi,

I want to hide the entire row in a pivot table in which the value(-s of that row is either zero, empty, or #NB.
In the beginning of the year there wuill be o1 value in the pivot table (month=1).
At the end of the year there will be 12 values in the pivot table (month=12).

I want to solve this using VBA but I don't know how.:confused:

Can someone help me with the VB code ?
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I tried this, but it hide much to many rows:

Private Sub Worksheet_Activate()

Dim HiddenRow&, RowRange As Range, RowRangeValue&

'*****************************
'< Set the 1st & last rows to be hidden >
Const FirstRow As Long = 12
Const LastRow As Long = 400

'< Set the columns that may contain data >
Const FirstCol As String = "D"
Const LastCol As String = "E"
'*****************************

ActiveWindow.DisplayZeros = False
Application.ScreenUpdating = False

For HiddenRow = FirstRow To LastRow

'(we're using columns D to E here)
Set RowRange = Range(FirstCol & HiddenRow & _
":" & LastCol & HiddenRow)

'sums the entries in cells in the RowRange
RowRangeValue = Application.Sum(RowRange.Value)

If RowRangeValue > 0 Then
'there's something in this row - don't hide
Rows(HiddenRow).EntireRow.Hidden = False
Else
'there's nothing in this row yet - hide it
Rows(HiddenRow).EntireRow.Hidden = True
End If

Next HiddenRow

Application.ScreenUpdating = True

End Sub
 
Upvote 0
monthNYabsenceCAabsencetotal
jan254166
feb334376
mar344579
apr0
may0
jun0
jul0
aug0
sep0
oct0
nov0
dec0
Why must you have a pivot table ?

<colgroup><col span="2"><col><col><col span="3"></colgroup><tbody>
</tbody>
 
Upvote 0
with this data I would plot a dynamic vertical bar chart so only 3 bars this month, next month the april bar would appear making 4 bars
 
Upvote 0
Because it is a pivot table already.
The measeure within the pivottable is calculated.
Sometimes the resault is #N/a.
You can hide the #N/a witthin the optionsbar of the pivottable.
The dimension however is still visable therefore I want to hide the complete row.

PS: There is no total column.
 
Upvote 0
ok, build a new table by copying elements of the pivot table, I often do this to make it look more professional - use eg if (or(t3="",t3="grand total"),"",T3)
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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