LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Dynamic Range for Pivot Table

Hi Rob,

You can do this one of two ways:

If your column is remaining the same, do the following:

Dim lastrow As Long
lastrow = (ActiveWorkbook.ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row)
Set xlData = Sheets("Sheet2").Range("A2:AC" & lastrow)
xlData.CopyFromRecordset aRS

- OR -

If your data changes in size for Column and rows, use this:

ActiveWorkbook.Names.Add Name:="PivotRange",
RefersToR1C1:="=OFFSET(Sheet2!R1C1,0,0,COUNTA(Shee t2!C1),COUNTA(Sheet2!R1))"

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase,
SourceData:="PivotRange").CreatePivotTable TableDestination:="",
TableName:="PivotTable2", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveWorkbook.ShowPivotTableFieldList = True

Hope this helps!

Jeff

"Rob" wrote:

I am reading information in from a SQL Server Database via OLE DB, putting
results into a worksheet which is then used to populate a Pivot Table. Since
the number of records returned can vary, I set the rows on the worksheet to
an arbitrary 25000. How do I get it so that once I read in the ADO
recordset, via
Set xlData = Sheets("Sheet2").Range("A2:AC25000")
xlData.CopyFromRecordset aRS
How do I/can I remove all blank rows?

Thanks

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic range in Pivot table Wanna Learn Excel Discussion (Misc queries) 4 July 2nd 07 08:08 PM
Using dynamic range to create pivot table cursednomore Excel Discussion (Misc queries) 5 March 12th 07 02:40 PM
Dynamic Range in a Pivot Table Chris C Excel Discussion (Misc queries) 0 June 27th 06 06:11 PM
crate group of date, with Dynamic Range in Pivot Table but not wor Tiya Excel Programming 3 June 20th 06 08:15 PM
Refreshing a Pivot Table from a dynamic range matpj[_4_] Excel Programming 2 October 20th 05 03:19 PM


All times are GMT +1. The time now is 10:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"