How to retrieve the last 5 rows of a Pivot Table using a Dynamic Range

rca

Board Regular
Joined
Mar 1, 2005
Messages
182
I have the following data in a Pivot Table in column C:

Value
10
20
30
40
50
60
70
80
90
100
Grand Total: 550

I would like to create a dynamic range that references only the last 5 records of the Pivot Table: 60, 70, 80, 90, 100.

The formula I'm using is:

=OFFSET($C$2,COUNT($C:$C),0,-5,1)

Unfortunately, this formula references the grand total row. Is there a way to amend the formula such that it only references the 5 rows directly above the grand total row? Thanks!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try
Code:
=OFFSET(C2,COUNT(C:C)-2,0,-5,1)
 
Upvote 0
I believe this formula will work if there are no blank cells. What if the data were as follows?

Value
10
20
30
40
50
60

80

100
Grand Total: 390

Is there a way to treat blank cells?
 
Upvote 0
Try
Code:
=OFFSET(C2,COUNT(C:C)-2+COUNTIF(C2:INDEX(C:C,MATCH(999999999999999,C:C)),""),0,-5-COUNTIF(C2:INDEX(C:C,MATCH(999999999999999,C:C)),""),1)


If you want to remove the zero(blank cells) form the array
Code:
=AGGREGATE(14,6,OFFSET($C$2,COUNT(C:C)-2+COUNTIF($C$2:INDEX(C:C,MATCH(999999999999,C:C)),""),0,-5-COUNTIF($C$2:INDEX(C:C,MATCH(999999999999,C:C)),""),1),ROW(INDIRECT("1:"&SUM(--(OFFSET($C$2,COUNT(C:C)-2+COUNTIF($C$2:INDEX(C:C,MATCH(999999999999,C:C)),""),0,-5-COUNTIF($C$2:INDEX(C:C,MATCH(999999999999,C:C)),""),1)<>0)))))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,098
Messages
6,128,812
Members
449,468
Latest member
AGreen17

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