ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Pivot Table & Dynamic data (https://www.excelbanter.com/excel-programming/308879-pivot-table-dynamic-data.html)

Sophism

Pivot Table & Dynamic data
 
I am importing data of variable length (rows) and never know the exact size.

How can I write a programme that in setting up the Pivot table identifies
the size of the data table in the same way that "currentregion" does for say
copy and paste.

I am told that dynamic range is the answer but dont know hoe to write syntax
to incorporate into the pivot element of the VBA programme.

Ta in advance for any help offerred



Dave Peterson[_3_]

Pivot Table & Dynamic data
 
You could use .current region in your code, too.

dim myPTRng as range
with worksheets("Sheet1")
set myptrng = .range("a1").currentregion
end with

Or if you know the last column (say W) and can pick out a column that always has
an entry (I used column A in my example):

dim myPTRng as range
with worksheets("Sheet1")
set myptrng = .range("a1:W" & .cells(.rows.count,"A").end(xlup).row)
end with

then later...

,sourcedata:=myptrng.address(external:=true), ...

If the data can change after you create the pivottable, you may want to look at
using a dynamic range. You can see some instructions at Debra Dalgleish's site:

http://www.contextures.com/xlNames01.html#Dynamic

Sophism wrote:

I am importing data of variable length (rows) and never know the exact size.

How can I write a programme that in setting up the Pivot table identifies
the size of the data table in the same way that "currentregion" does for say
copy and paste.

I am told that dynamic range is the answer but dont know hoe to write syntax
to incorporate into the pivot element of the VBA programme.

Ta in advance for any help offerred


--

Dave Peterson



All times are GMT +1. The time now is 08:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com