Consulting

Results 1 to 4 of 4

Thread: Need a little help please

  1. #1

    Need a little help please

    I run the same reports everyday and would like to use a generic VBA code that selects all my data and creates the pivot table. I've recorded the MACRO:

    - I need the data range selected automatically to be allow any data amount
    - I need the data range to be selected automatically
    - The sheet should not matter
    - Finally I would like to name the sheet

    Sheets.Add
        ActiveWorkbook.Worksheets("Sheet1").PivotTables("PivotTable26").PivotCache. _
            CreatePivotTable TableDestination:="Sheet4!R3C1", TableName:="PivotTable27" _
            , DefaultVersion:=xlPivotTableVersion15
        Sheets("Sheet4").Select
        Cells(3, 1).Select
        With ActiveSheet.PivotTables("PivotTable27").PivotFields("Date Opened")
            .Orientation = xlRowField
            .Position = 1
        End With
        With ActiveSheet.PivotTables("PivotTable27").PivotFields("Date Opened")
            .Orientation = xlColumnField
            .Position = 1
        End With
        With ActiveSheet.PivotTables("PivotTable27").PivotFields("Queue")
            .Orientation = xlRowField
            .Position = 1
        End With
        With ActiveSheet.PivotTables("PivotTable27").PivotFields("Sub Queue")
            .Orientation = xlRowField
            .Position = 2
        End With
        With ActiveSheet.PivotTables("PivotTable27").PivotFields("Status")
            .Orientation = xlColumnField
            .Position = 1
        End With
        ActiveSheet.PivotTables("PivotTable27").AddDataField ActiveSheet.PivotTables( _
            "PivotTable27").PivotFields("Source"), "Count of Source", xlCount
        With ActiveSheet.PivotTables("PivotTable27").PivotFields("Queue")
            .PivotItems("(blank)").Visible = False
        End With
    End Sub
    Last edited by Paul_Hossler; 03-27-2017 at 05:42 PM.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,738
    Location
    I added [CODE] ... [/CODE] tags around your code. You can use the [#] icon to do that

    It makes the macro easier to read

    Can you attach a sample workbook with the data and what you want the PT to look like?
    ---------------------------------------------------------------------------------------------------------------------

    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

  3. #3
    Due to the sensitive nature of the data I cannot.

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,738
    Location
    Put in fake data so we can see the structure and formats at least
    ---------------------------------------------------------------------------------------------------------------------

    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
  •