Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Removing and Adding Pivot Table Fields

Hello Everyone,

I am working with VBA to create a pivot table, and have done just fine
so far. However, I need to create a two buttons that will run the
following macros:
1. A macro that will remove the selected header (either row or
column) from the pivot table.

2. A macro that will put the removed header back into the pivot
table.

I need to be able to click on the header (whether its the row or column
header) and then press the button to remove it from the table. The
second button should then add that header back into the table. My code
for creating the table is fine, I just need to work out the buttons.
Below is what I have so far. I was think that if I had variable for
the header name it would be able to tell which header to remove (so I
used Set iField = ActiveCell.Value), I also tried ActiveCell.Text. All
I need to do is put the text in the selected field into the PivotFields
range to make it hidden. However, I keep getting an error (Compile
Error: Object Required) on the line Set iField = ActiveCell.Value.
Below is my current code. Any help would be much appreciated.

Sub PivotTable()

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:=
_
"'Pivot Table Data'!R1C1:R1892C7").CreatePivotTable
TableDestination:="", _
TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3,
1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable1").AddFields
RowFields:="Product", _
ColumnFields:="Location"

ActiveSheet.PivotTables("PivotTable1").PivotFields ("Sales").Orientation
= _
xlDataField
ActiveWorkbook.ShowPivotTableFieldList = False
End Sub

____________________________________________

Public Sub RemoveHeader()
Dim iField As String
Dim PT As PivotTable

Set iField = AcvtiveCell.Value

PT.PivotFields("iField").Orientation = xlHidden

End Sub
___________________________________________

Public Sub AddHeader()
Dim iField As Integer
Dim PT As PivotTable

With PT.PivotFields("iField")
If iField = "Location" Then
.Orientation = xlColumnField
Else
.Orientation = xlRowField
End If

End With

End Sub

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
Problem inserting calculated pivot fields into Pivot Table (2007) wamiller36 Excel Discussion (Misc queries) 1 March 5th 10 11:40 PM
fields names do not show in excel 2007 pivot table fields list marlo17 New Users to Excel 2 December 1st 08 01:25 PM
Adding multiple fields to a Pivot table at one time GSeattle Excel Discussion (Misc queries) 1 May 30th 07 06:14 PM
number of fields in the row fields in pivot table UT Excel Discussion (Misc queries) 0 April 13th 06 01:17 AM
removing (All) from Pivot Table Tim Excel Programming 4 May 19th 05 11:55 PM


All times are GMT +1. The time now is 12:10 AM.

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

About Us

"It's about Microsoft Excel"