Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Pivot Table, Variable Inputs

I have inputs form a ListBox, and a simple index function:
=INDEX($A$8:$A$59,$B$7)
to get the items in the box to display in a cell as names instead of
numbers. The names go into cell C5, which I named VarInput. I thought I
could reference this cell for a Pivot Table, and it seems to almost work, but
it doesn't quite work. Below is the code. Can someone please tell me what
is wrong?

I'm pretty sure I need code like this to reference the specific cell:
..PivotFields(Sheets("Summary").Range("VarInput"). Value)

The code fails in two places, indicated below (I know about the second one
because I commented out the first one and reran the code and got a second
error).

Sub PivotTableInputs()

Sheets("MergeSheet").Select
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"MergeSheet!R1C1:R375C24").CreatePivotTable TableDestination:="",
TableName _
:="PivotTable3", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select

ActiveSheet.PivotTables("PivotTable3").PivotFields (Sheets("Summary").Range("VarInput").Value).Subtot als = Array( _
False, False, False, False, False, False, False, False, False,
False, False, False)
ActiveSheet.PivotTables("PivotTable3").AddFields
RowFields:=Range("VarInput")

ActiveSheet.PivotTables("PivotTable3").PivotFields (Sheets("Summary").Range("VarInput").Value) = xlDataField
ActiveWorkbook.ShowPivotTableFieldList = True

'first problem

ActiveSheet.PivotTables("PivotTable3").PivotFields (Sheets("Summary").Range("VarInput").Value).AutoSo rt
xlDescending , Range("VarInput")

'second problem
With
ActiveSheet.PivotTables("PivotTable3").PivotFields (Sheets("Summary").Range("VarInput").Value)
.PivotItems("(blank)").Visible = False
End With

Charts.Add
With ActiveChart.ChartGroups(1)
.Overlap = 100
.GapWidth = 0
.HasSeriesLines = False
.VaryByCategories = False
End With
End Sub

Can someone please tell me what is wrong?


Regards,
Ryan--


--
RyGuy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Pivot Table, Variable Inputs

Resolved!!
http://www.microsoft.com/office/comm...sloc=en-us&p=1

PS, thanks for the help Ivan!!

Regards,
Ryan---

--
RyGuy


"ryguy7272" wrote:

I have inputs form a ListBox, and a simple index function:
=INDEX($A$8:$A$59,$B$7)
to get the items in the box to display in a cell as names instead of
numbers. The names go into cell C5, which I named VarInput. I thought I
could reference this cell for a Pivot Table, and it seems to almost work, but
it doesn't quite work. Below is the code. Can someone please tell me what
is wrong?

I'm pretty sure I need code like this to reference the specific cell:
.PivotFields(Sheets("Summary").Range("VarInput").V alue)

The code fails in two places, indicated below (I know about the second one
because I commented out the first one and reran the code and got a second
error).

Sub PivotTableInputs()

Sheets("MergeSheet").Select
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"MergeSheet!R1C1:R375C24").CreatePivotTable TableDestination:="",
TableName _
:="PivotTable3", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select

ActiveSheet.PivotTables("PivotTable3").PivotFields (Sheets("Summary").Range("VarInput").Value).Subtot als = Array( _
False, False, False, False, False, False, False, False, False,
False, False, False)
ActiveSheet.PivotTables("PivotTable3").AddFields
RowFields:=Range("VarInput")

ActiveSheet.PivotTables("PivotTable3").PivotFields (Sheets("Summary").Range("VarInput").Value) = xlDataField
ActiveWorkbook.ShowPivotTableFieldList = True

'first problem

ActiveSheet.PivotTables("PivotTable3").PivotFields (Sheets("Summary").Range("VarInput").Value).AutoSo rt
xlDescending , Range("VarInput")

'second problem
With
ActiveSheet.PivotTables("PivotTable3").PivotFields (Sheets("Summary").Range("VarInput").Value)
.PivotItems("(blank)").Visible = False
End With

Charts.Add
With ActiveChart.ChartGroups(1)
.Overlap = 100
.GapWidth = 0
.HasSeriesLines = False
.VaryByCategories = False
End With
End Sub

Can someone please tell me what is wrong?


Regards,
Ryan--


--
RyGuy

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
Find a single value from tables by selecting two variable inputs? jj023 Excel Worksheet Functions 8 February 17th 10 01:40 AM
Using a variable to add fields to a pivot table Gwen Excel Programming 0 July 9th 07 11:56 PM
Can't set pivot table object variable Jeff S[_2_] Excel Programming 0 February 13th 07 10:53 PM
work roster with variable inputs foxwave Excel Discussion (Misc queries) 0 December 3rd 04 07:39 PM
Pivot Table - Object variable or with block variable not set? George Nicholson[_2_] Excel Programming 1 April 16th 04 09:12 PM


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