View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Randy Harmelink Randy  Harmelink is offline
external usenet poster
 
Posts: 122
Default How to automatically create and populate worksheets?

One option in a Pivot Table is to "ShowDetail" of any intersection of
data within the Pivot Table. You could use that function to create all
of your extracted worksheets. For example, a macro something like
this:

Sub Test()
'-------- Create basic pivot table of column A fields
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:=
_
"Sheet1!A:C").CreatePivotTable TableDestination:="",
TableName:= _
"PivotTable2", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3,
1)
With ActiveSheet.PivotTables("PivotTable2")
.ColumnGrand = False
.RowGrand = False
.AddFields RowFields:="Group"
.PivotFields("Group").Orientation = xlDataField
.PivotFields("Group").PivotItems("(blank)").Visibl e = False
End With
ActiveWorkbook.ShowPivotTableFieldList = False
Application.CommandBars("PivotTable").Visible = False
'-------- Showdetail of each column A field value
Set ws = ActiveSheet
For iRow = 5 To 500
ws.Activate
If ws.Cells(iRow, 1).Value = "" Then Exit For
ws.Cells(iRow, 2).ShowDetail = True
ActiveSheet.Name = ws.Cells(iRow, 1).Value
Next iRow
End Sub