Pivot Table
Results 1 to 4 of 4

Thread: Pivot Table

  1. #1
    Board Regular
    Join Date
    Dec 2004
    Posts
    161
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Pivot Table

    Hi there
    I'm sure that this is an easy fix but I'm having difficulty figuring it out. I have recorded a macro that created a pivot table. The macro works great. However, I have a few questions in the macro below. Right now, the range is fixed. Is there a way to make the range not fixed in my macro, in case I need to add more rows. I don't want to make my worksheet that the Pivot Table takes the data from into a table.

    I also have 5 fields. I want to be able to sort by each field but my pivot table won't allow me to do that. It only allows me to sort by my first field. Is there a way for me to sort by each of the 5 fields? Most of the fields have dollar amounts in them except for the first field. Thanks

    Sub PivotTable()

    Sheets("Sheet3").Select
    Cells.Select
    ActiveWindow.SmallScroll Down:=-9
    Selection.Clear
    Range("A1").Select

    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "Sheet2!R1C1:R373C29", Version:=6).CreatePivotTable TableDestination:= _
    "Sheet3!R3C1", TableName:="PivotTable3", DefaultVersion:=6
    Sheets("Sheet3").Select
    Cells(3, 1).Select

    End Sub

  2. #2
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,729
    Post Thanks / Like
    Mentioned
    65 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Pivot Table

    Try this,

    To have a dynamic range:

    Code:
    Sub PivotTable()
      Dim lr As Long
      Sheets("Sheet3").Select
      Cells.Clear
      lr = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row
      ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Sheet2!R1C1:R" & lr & "C29", Version:=6).CreatePivotTable TableDestination:= _
        "Sheet3!R3C1", TableName:="PivotTable3", DefaultVersion:=6
    End Sub
    Record a macro ordering the fields you need and paste the macro here to review it.
    Regards Dante Amor

  3. #3
    Board Regular
    Join Date
    Dec 2004
    Posts
    161
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Pivot Table

    Hi Dants

    Thanks for the code. I will give it a try.

  4. #4
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,729
    Post Thanks / Like
    Mentioned
    65 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Pivot Table

    You're welcome, leave me if you have any questions.
    Regards Dante Amor

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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