Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Pivot Tables and VBA

Hi All

I do a lot of Excel Query SQL DB bits and bobs and because of the
complexity of my latest report I need to put this data into a pivot table.
I want to make it as auto as possible so the way I want to do it is as
follows:

Worksheet 1 (called "Enter Date Range") asks the user to enter a start date
in cell B1 and an end date in cell B2 before clicking a simple form button.

This form button executes the following Macro code module:

With ActiveWorkbook.PivotCaches.Add(SourceType:=xlExter nal)
.Connection = _
"ODBC;DSN=SQL;UID=rob;PWD=;WSID=Me;DATABASE=Accoun ts;AutoTranslate=No;UsePro
cForPrepare=0"
.CommandType = xlCmdSql
.CommandText = Array( <<< my SQL DB query incoprating my start and
end at values from the first worksheet )
.CreatePivotTable TableDestination:="", TableName:="PivotTable1"
End With
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable1").SmallGrid = False
With ActiveSheet.PivotTables("PivotTable1").PivotFields ("NAME")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields ("NAME2")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields ("QUANTITY")
.Orientation = xlDataField
.Position = 1
End With

Although the above generates the required report, my problems are as
follows:

1) It keeps putting the above pivot table into a new worksheet everytime. I
want it to go to one specific worksheet called "Report" and when the user
goes back and enters a new date range (on the "Enter Date Range" worksheet)
I want it to simply execute and use the same "Report" worksheet to display
the new pivot report data without creating orphaned resources. Any ideas on
how to do this?

2) I'm using Excel 2000 on a PC and annoyance no. 1 is that every time the
above creates the pivot table it shows the Pivot toolbar with the extended
grey bottom bit showing the extra fields (the Display/Hide Fields button at
the far right toggles the display of this). When this is displayed it also
mucks about with the display of the report, eg blue borders and things. I
don't want any of this can the toolbar be stopped from doing this?

3) Major annoyance no.2 why the hell can't I remove the grey data field
boxes from the top of my pivot report???? It makes the report look crap and
if I click on them and select the Hide option it loses my data. The
unsightly options I am talking about are as follows:

<Sum of of a Field <Drop Down menu of a Field
<Drop Down menu of a Field my data my data
my data my data my data
my data my data my data

I'm talking about the 3 encapsulated in the <'s.

An end user will always click on these and cock the report up, any ideas on
how to hide these successfully without losing the data???

Many thanks.

Laphan


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 196
Default Pivot Tables and VBA

1) It keeps putting the above pivot table into a new
worksheet everytime.

The problem is that you are repeatedly adding a new
PivotCache and calling the .CreatePivotTable method...
thus, it creates a new pivot table each time.

To have only one pivot table, either delete the original
one before you create the new one, or change the source of
the existing one (if necessary) and refresh it.

2) Pivot toolbar with the extended grey bottom bit


I think your talking about the pivot table command bar...
just use this code to turn it off:

Application.CommandBars("PivotTable").Visible = False


3) Major annoyance no.2 why the hell can't I remove the

grey data field boxes from the top of my pivot report????

I'm not sure if you can remove them in anyway, but you can
copy the data from the userange of the pivot table sheet,
and then use pastespecial to put just the data in another
place.

like this:


Sheets("pvTable").UsedRange.Copy
ActiveCell.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False


Would that help?





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Pivot Tables and VBA

Hi Mark

Many thanks for your valued feedback.

I'm no where near a VBA guru so could you explain how I achieve point 1.

All I want to do is put the new query into the same worksheet and not create
a gazillon instances (like you say) each time they run the report.

The Macro code that I have seems to be straightforward apart from the bit
where it keeps adding a new table to a new worksheet. How do I force it to
go to my worksheet and not create new instances???

Thanks

Laphan


mark wrote in message
...
1) It keeps putting the above pivot table into a new

worksheet everytime.

The problem is that you are repeatedly adding a new
PivotCache and calling the .CreatePivotTable method...
thus, it creates a new pivot table each time.

To have only one pivot table, either delete the original
one before you create the new one, or change the source of
the existing one (if necessary) and refresh it.

2) Pivot toolbar with the extended grey bottom bit


I think your talking about the pivot table command bar...
just use this code to turn it off:

Application.CommandBars("PivotTable").Visible = False


3) Major annoyance no.2 why the hell can't I remove the

grey data field boxes from the top of my pivot report????

I'm not sure if you can remove them in anyway, but you can
copy the data from the userange of the pivot table sheet,
and then use pastespecial to put just the data in another
place.

like this:


Sheets("pvTable").UsedRange.Copy
ActiveCell.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False


Would that help?







  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 196
Default Pivot Tables and VBA

Hey, sorry I didn't think to look back here until this
afternoon... hope you're still looking.

You wrote:
I'm no where near a VBA guru so could you explain how I

achieve point 1.


Try this...

assuming that the sheet where your pivot table is located
is called pvTable, add a code line:

Sheets("pvTable").cells.delete

That will eliminate the original pivot table, but not
delete the sheet itself.

Then, in your existing code, where it said:

TableDestination:=""

change that line to:

TableDestination:= Sheets("pvTable").Range("a3")


After those two changes, your code should be able to run
repeatedly and only end up with one pivot table.






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
Building pivot tables in Excel 2007 based on existing pivot tables? [email protected] Excel Discussion (Misc queries) 4 December 26th 07 08:05 PM
Pivot Table Data Adding contents of two pivot tables and param que Roundy Excel Discussion (Misc queries) 0 July 2nd 07 10:20 PM
Average Calculations from Pivot Tables - Get Pivot Data? Calc Fiel westy Excel Worksheet Functions 5 March 10th 07 01:31 AM
How does the term 'pivot' apply to Excel's Pivot tables and Pivot. stvermont Excel Discussion (Misc queries) 1 February 17th 05 01:34 AM
Pivot tables-controlling user interaction with pivot tables Sindhura Excel Programming 0 August 27th 03 02:10 PM


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