Pivot Table

pincivma

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

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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.
 
Upvote 0
You're welcome, leave me if you have any questions.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top