Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel vba pivot table programming

I have an excel workbook with 2 sheets and a vba module. I use ADO to connect
to a sql server 2000 to collect some data. Download of data to excel is
controlled from a combobox and some buttons on sheet1. The user selects a
customer (in the combobox) and downloads from 400 to 5000 records from sql
server. The records are visible on sheet1, so the operator can browse the
data.

Om sheet2 there is a pivot table that shows data from sheet1. Unfortunately
the pivot table is not correctly updated when the operator deletes old data
and downloads some new on sheet1. This seem to happen if the pivot table was
established with 500 records on sheet1. In the next case there may be 5000
records, and only a fraction of these are shown in the pivot table.

"Refresh data" on the Excel Data menu do not fix the problem. It seems I
need to reset the data source for the pivot table, and this have to be done
without changing the structure (column-, row-, and page-fields) on the pivot
table. How can this be done in VBA-code?

Regards

Tore G.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Excel vba pivot table programming

This may help:

Sub PivotRange()

Dim rowCount As Long

Sheets("Data").Select
Range("A1").Select
rowCount = Selection.CurrentRegion.Rows.Count

Sheets("Pivot").Select
Range("A3").Select 'must be cell in pivottable
ActiveSheet.PivotTableWizard SourceType:=xlDatabase _
, SourceData:="Data!R1C1:R" & rowCount & "C3"

End Sub

The routine first goes to the data sheet and counts the number of rows. It
then selects a cell in the pivot table and makes use of the Pivot Table
Wizard to change the data range. Note my data is only 3 columns wide so you
will have to adapt the last line - & "C3" - to your situation.

Regards
Rowan

" wrote:

I have an excel workbook with 2 sheets and a vba module. I use ADO to connect
to a sql server 2000 to collect some data. Download of data to excel is
controlled from a combobox and some buttons on sheet1. The user selects a
customer (in the combobox) and downloads from 400 to 5000 records from sql
server. The records are visible on sheet1, so the operator can browse the
data.

Om sheet2 there is a pivot table that shows data from sheet1. Unfortunately
the pivot table is not correctly updated when the operator deletes old data
and downloads some new on sheet1. This seem to happen if the pivot table was
established with 500 records on sheet1. In the next case there may be 5000
records, and only a fraction of these are shown in the pivot table.

"Refresh data" on the Excel Data menu do not fix the problem. It seems I
need to reset the data source for the pivot table, and this have to be done
without changing the structure (column-, row-, and page-fields) on the pivot
table. How can this be done in VBA-code?

Regards

Tore G.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Excel vba pivot table programming

Hi,
How about using a dynamic range name for the source of the pivot
table...

something like..

=offset(Sheet1!$A$1,0,0,counta($A:$A),Counta($1:$1 ))
Hth,
Oli

Reply
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
how to create pivot table from existing pivot table in excel 2007 Udayraj Dhulekar Excel Discussion (Misc queries) 2 July 8th 13 08:22 PM
Excel Food Price Table, Programming, Is This Table All Right? Davi Excel Discussion (Misc queries) 2 June 3rd 07 12:24 PM
Pivot Table Programming Marvin Excel Programming 1 January 25th 05 10:54 PM
Pivot Table Programming OrrLyfe Excel Programming 3 November 1st 04 12:44 AM
Pivot table Programming Kris Excel Programming 1 October 5th 04 09:03 PM


All times are GMT +1. The time now is 05:18 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"