Pivot Table

pincivma

Board Regular
Joined
Dec 12, 2004
Messages
199
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
 

Some videos you may like

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,181
Office Version
2007
Platform
Windows
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.
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,181
Office Version
2007
Platform
Windows
You're welcome, leave me if you have any questions.
 

Watch MrExcel Video

Forum statistics

Threads
1,102,344
Messages
5,486,299
Members
407,538
Latest member
kbendelac

This Week's Hot Topics

Top