Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Pivot Table from Filtered Data

It doesn't matter if the source table is filtered or not -- the pivot
table is created from the entire table, including any hidden rows.

You could use an Advanced Filter to extract the results to a different
area of the workbook, and create the pivot table from the extracted data.

Bigfoot17 wrote:
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



--
Debra Dalgleish
Contextures
www.contextures.com/tiptech.html
Blog: http://blog.contextures.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 434
Default Pivot Table from Filtered Data

hi, !

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...


it is not so pristine either, but you might want to give a try to the following (for an existing PT):

- add a column to your source range using something like: =subtotal(2,e2)
put some title such as "visible" -???-

- use the PT-Wizard, backward to include the above (new) column as a page-field (and finish the PTW)

- now, after filtering, you can "play" by refreshing your PT and/or "filtering" over the (new) page-field

hth,
hector.


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 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:09 PM.

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"