Pivot Table

pincivma

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

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
7,919
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
7,919
Office Version
2007
Platform
Windows
You're welcome, leave me if you have any questions.
 

Forum statistics

Threads
1,078,442
Messages
5,340,305
Members
399,366
Latest member
ahmed elsaid

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top