Dim oPiv_range As Range
Set oPiv_range = Range("A1").CurrentRegion
oPiv_range would be the range for the pivot table,
Assuming ur data starts in range("A1")
You could base a pivot table on a named range,
(Insert Menu..Name..Define), and
define the Named Range with an offset formula
so it "knows how many rows deep it is."
The OFFSET does this well. Here's an example:
Definition for "pivot_data_range"
=OFFSET(Data!$A$1:$H$1,0,0,COUNTA(Data!$H:$H))
[put this exact formula into the Named
Range definition, but change the sheet name -
here it is Data]
The 'translation' is as follows:
start with cells a1:h1
[Data!$A$1:$H$1,]
dont move any rows or colums
[0,0,]
the 'depth' of the named range is based
on the number of non-blank rows in column H:
[COUNTA(Data!$H:$H)]
The generic definition for offset is:
OFFSET(reference,rows, cols,height,width)
Remember that this definition relies on all the
cells coming into column H having a value! Its
best to choose a column that will always have
values coming into it. This way, whether you have
10 rows coming in or 10,000 rows, the pivot table
is based on the exact number of variable rows.