LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Pivot Table from Filtered Data

I am struggling trying to create a pivot table from filtered data. I am
enclosing the sub but am scared to death to do it because I now it is not
pristine code. I believe the problem is that I successfully filter the data
but then I select all of the rows for the pivot table rather than just the
filtered rows. Any help is appreciated.

Sub Create_2nd_Pivot_Table()
'
'
'Filter for Month selected
xMonth = Sheets("Stats").Range("E37").Value
yMonth = xMonth + 1
xYear = Sheets("Stats").Range("D37").Value
If xMonth = 12 Then
yYear = xYear + 1
Else
yYear = xYear
End If
BegMonth = xMonth & "/1/" & xYear
EndMonth = yMonth & "/1/" & yYear


Sheets("Log").Select
'Selection.AutoFilter Field:=7, Criteria1:="=9/1/2008",
Operator:=xlAnd, _
Criteria2:="<10/1/2008"
Selection.AutoFilter Field:=7, Criteria1:="=" & BegMonth,
Operator:=xlAnd, _
Criteria2:="<" & EndMonth

' Clear old Pivot table area on Work Col a-l
Sheets("Work").Visible = True
Sheets("Work").Select
Range("A4:l500").Clear
Range("A4").Select

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"Log!R5C1:R500C10").CreatePivotTable TableDestination:= _
"Work!R4C1", TableName:="PivotTable5", DefaultVersion:= _
xlPivotTableVersion10
ActiveSheet.PivotTables("PivotTable5").ColumnGrand = False
ActiveWorkbook.ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("PivotTable5").PivotFields ("Circuit")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable5").PivotFields ("Trainer")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable5").AddDataFiel d
ActiveSheet.PivotTables( _
"PivotTable5").PivotFields("Course Hours"), "Sum of Course
Hours", _
xlSum
ActiveWorkbook.ShowPivotTableFieldList = False
Range("A1").Select
Sheets("Work").Visible = False
Application.ScreenUpdating = False
Sheets("Stats").Activate
Range("F37").Select
End Sub
 
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 can i get a sum of the data filtered in a pivot table tarabull Excel Discussion (Misc queries) 1 March 26th 09 02:13 PM
Using Pivot Table to Display Filtered Data Only Dawg House Inc Excel Discussion (Misc queries) 6 February 14th 07 01:03 AM
Macro To Delete Filtered Pivot Table Data Roger[_21_] Excel Programming 0 June 1st 06 04:58 PM
Pivot Table - display filtered data Jeff M Excel Programming 0 October 16th 05 05:50 PM
filtered recodset to pivot table (or not) Robin Hammond[_2_] Excel Programming 2 July 19th 04 07:44 AM


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