Results 1 to 20 of 20

Thread: RE: Pivot table creation in existing sheet- VBA issues

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #17
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,888
    Location
    Try this, but I have to say that I don't see where you're going with this


    Option Explicit
    
    
    Sub createPivotTables()
        Dim rData As Range
        Dim wsPT As Worksheet, wsItem As Worksheet
        Dim myPivotTable As PivotTable
     
        For Each wsItem In ActiveWorkbook.Worksheets
            If wsItem.Name = "Main Data" Then GoTo NextSheet    '   space in from of tab name
            If wsItem.Visible <> xlSheetVisible Then GoTo NextSheet '   sheet2 is hidden
     
            Set rData = wsItem.Cells(1, 1).CurrentRegion
        
            Set myPivotTable = ThisWorkbook.PivotCaches.Create(SourceType:=xlDatabase, _
                SourceData:=rData).CreatePivotTable(TableDestination:=wsItem.Cells(1, 1).Offset(0, rData.Columns.Count + 2))
     
            With wsItem.PivotTables(1)
                .PivotFields("OrderDate").Orientation = xlRowField
                .PivotFields("Region").Orientation = xlRowField
                .PivotFields("Rep").Orientation = xlRowField
                .PivotFields("Item").Orientation = xlRowField
                .PivotFields("Units").Orientation = xlRowField
                .PivotFields("Unit Cost").Orientation = xlRowField
                    With .PivotFields("Total")
                        .Orientation = xlDataField
                        .Position = 1
                        .Function = xlSum
                        .NumberFormat = "#,##0.00"
                    End With
            
                .RowAxisLayout xlTabularRow
                
                .PivotFields("OrderDate").Subtotals = Array(False, False, False, False, False, False, False, False, False, False, False, False)
                .PivotFields("Region").Subtotals = Array(False, False, False, False, False, False, False, False, False, False, False, False)
                .PivotFields("Rep").Subtotals = Array(False, False, False, False, False, False, False, False, False, False, False, False)
                .PivotFields("Item").Subtotals = Array(False, False, False, False, False, False, False, False, False, False, False, False)
                .PivotFields("Units").Subtotals = Array(False, False, False, False, False, False, False, False, False, False, False, False)
                .PivotFields("Unit Cost").Subtotals = Array(False, False, False, False, False, False, False, False, False, False, False, False)
                .PivotFields("Total").Subtotals = Array(False, False, False, False, False, False, False, False, False, False, False, False)
                
                .ColumnGrand = False
                .RowGrand = False
                
                .PivotFields("OrderDate").AutoSort xlAscending, "OrderDate"
                .PivotFields("Region").AutoSort xlAscending, "Region"
                .PivotFields("Rep").AutoSort xlAscending, "Rep"
            End With
        
    NextSheet:
        Next
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •