How To Create Pivot Using Macro

Apr 21, 2014

I am trying to create a pivot table using macro. In order to accommodate for changes in data, I used dynamic range.

See below for the step I took:

1) Create dynamic range using offset formula (=OFFSET('CommTest Booking Selections Gre'!$A$2,0,0,COUNTA('CommTest Booking Selections Gre'!$A:$A),21)
2) Record Macro
3) While recording: created pivot table using dynamicrange, added a new column next to the pivot to get additional data (if formula), and formatted.
4) Stop recording and delete sheet 1(where pivot was created) and used the shortcut to re-create the pivot

Once I do step 4, I get an error message: Run-time error '5': Invalid procedure call or argument and highlights the area when I click "debug":

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"DynamicRange", Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="Sheet1!R3C1", TableName:="PivotTable11", DefaultVersion _
:=xlPivotTableVersion14

Please see below for the entire VBA codes:

Also note that, I already saved my file in .xlsm format so macro should work.

Sub Over50KbyPO()
'
' Over50KbyPO Macro
' Total order value >$50K by PO
'
' Keyboard Shortcut: Ctrl+Shift+T
'
Sheets.Add

[Code]...

View 1 Replies


ADVERTISEMENT

Macro To Create Pivot Table?

Jun 3, 2014

Can record the all those actions which we need to do on a regular basis. In my work i have to create the pivot table to a data which gets changed every day but the data sequence remains the same.

I have tried to record the macro for the pivot table but when i tried to run the macro again then the below error message comes.

"run time error 5" "Invalid procedure call or argument" when i click on debug then the below macro program is highlighted in yellow color.

View 1 Replies View Related

Create Pivot Table Using Macro

Jul 25, 2014

I got this code from another old old thread, is there a way that the pivot is already setup like column A is already in Row Labels, B is for Column Labels and C to Values.

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
SourceData:= _[a1].CurrentRegion.Address).CreatePivotTable
TableDestination:= _"", TableName:="PivotTable1"ActiveSheet.PivotTableWizard

[Code] ......

View 1 Replies View Related

Macro Create Pivot Tables?

Jun 27, 2007

I created a macro by using the macro recorder. It creates some columns and formulas and does some formatting, then it is to take the data and create some pivot tables.

for some reason it gets stuck on the first pivot table. It creates it, but it wont add the first field to the table.

View 4 Replies View Related

Macro To Create Pivot Tables

Oct 22, 2006

I have recorded a Macro to create Pivot Tables, I would like this to run in any workbook. The problem is that every time a Pivot Table is generated Excel alters the number of the table(Pivot Table options). This then does not match that in the Macro as below("PivotTable1").

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Sheet1!R1C1:R37C6").CreatePivotTable TableDestination:="", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet. Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("GAME")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("LANGUAGE")
.Orientation = xlRowField
.Position = 2

View 2 Replies View Related

Recording Macro That Will Create Pivot Table?

Feb 11, 2014

Fixing a macro that i recorded in order to generate a pivot table on the same sheet and the same exact location every time. it seems that the macro fails every time i try to run and i'm thinking it has to do with the table reference. Again i want the table in the same sheet and the same location every time i run the macro. this is the recorded code so far.

View 1 Replies View Related

Macro Parameters To Create Pivot Table

Nov 30, 2006

I have a data table that contains 180 dates e.g. 9/30/06, 10/31/06 etc. When I'm creating the pivot table via a macro I'd like to have (2) parameters to enter at run time, those being Beginning Date and Ending Date.

View 9 Replies View Related

Macro Recorder To Create A Pivot Table

Sep 30, 2008

I used the macro recorder to create a pivot table, but to verfity that it works.

I get a "Add fields method of Pivot Table class failed"..

and this was highlighted:

ActiveSheet.PivotTables("PivotTable2").AddFields RowFields:=Array("Warehouse" _
, "Product", "Description", "Data")

View 9 Replies View Related

Macro To Create Pivot Table On Active Worksheet?

Jun 20, 2012

I have recorded a macro to create a pivot table. I thought I had it so that it would create the pivot from the active worksheet only. But looking at the code, it is picking up the sheet name from the one I recorded it from

Code:
Sub SalPiv()
'
' SalPiv Macro
' Macro recorded 20/06/2012 by imccormick

[Code].....

View 1 Replies View Related

Macro To Create Pivot Tables And Sort Out Data In Other Worksheet

May 19, 2009

The first sheet is the row data given to me, the second one is where I want my data to be analysed automatically by macros.

I managed to create a pivot table manually to give me the info I want but then I still have to copy all the results from the pivot table sheet to my analysis sheet.

How can I create a macro able to do all that by it self? I tried to record a macro using the recorder but then when I try to play it it gives me an error straight at the beginning in the definition of the pivot table I think.

An example of what I want the pivot table to do is:
in the first sheet, go in the small table in column K and L, take the value of L1, then in the row data in column A to J, in column C look for the value in L1, once found, look for the value 1 in column J then do the average on the values in column E and put the result in my second sheet in cell F5
then do the same but look for 2 in column J and put it in F8, then 3 in F11, ... until 7 found (the data is in ss.000 and so the results in the second sheet should be formated the same way)
then do the same all over again for value in L2
etc etc etc

this should be done for the 6 values in column L, each having values up to 7 in the J column.

Then I need to do the same for other columns and not only averages but minimums as well but I can adapt the code I think.

View 14 Replies View Related

Macro Code Create Pivot Table Based On Dynamic Source Data

Nov 28, 2006

The "Sum" sheet can change its number of rows. The pivot table is based on it. I'm having trouble with the SourceData portion of the code in my macro ....

View 9 Replies View Related

How To Use Pivot Cache To Create Another Pivot Table Instance On A Different Worksheet

Jul 7, 2014

I have a pivot table that I created and now I want to use the same pivot cache to create another pivot table instance on a different worksheet. how can I do that? My first worksheet gets saved as "OO By buyer" and now I want to create a new worksheet and drop the next pivot there.

View 1 Replies View Related

Create Pivot Table: Cannot Open Pivot Table Source File

Jan 4, 2010

I'm trying to write a macro that will create a pivot table, and am getting an Error code 1004: Cannot Open Pivot Table Source File "Sheetname". My code is below. I've tried to note what each section does, and it all seems to work well except for the Pivot Table creation.

View 14 Replies View Related

How To Create A Pivot Chart

Apr 7, 2014

I am trying to create a pivot chart that show the average response times in hour but for some reason my charts looks not right. The axis show a max of 1 but the graph itself showed us up to 17. I think easier to explain if I attached the worksheet.

View 2 Replies View Related

Create Pivot Table In New Tab With New Name

May 1, 2009

1) I want to create a pivot table in a new tab that has both the prefix “ENG” and the date of creation as the new name of the tab every time a new table is required, using the example headers highlighted in the attached file.

2) Then if possible format the table as in the example, i.e. bordered cells for all the data and the dates only aligned to the right. Example in tab “Eng 01 05 09”

No 1 is the most import question I would like help on. Formatting is not crucial. This is only to make the table easier on the “eye of the beholder”, I am writing this spreadsheet for people who have less knowledge than myself and would like to keep it as simple as possible, (run a macro and get the results).

View 11 Replies View Related

Create Macro That Can Create Dynamic Copy / Paste Loop?

Feb 12, 2014

I need to create a macro that can create a dynamic copy/paste loop. So far what I have is horribly inefficient. Each row in colmn A(minus the header) has a unique number in it. For each unique number, I need to paste it based on the number of column headers in row 1(minus column A). So, if there are 20 column headers, I need to copy cell A2 and paste it 19 times in another sheet. Then, I need to move to the next number in column A and do the same thing. Here's what I have:

[Code] .........

You can see that this is not dynamic. If I add another row to my table and rerun the macro, it will not catch it. I've attached a sample file to show you the big picture of what I'm trying to do. The data that I have is in Sheet1, and I'm trying to get it into the format in Sheet3. Rows/columns will be periodically added to the table in Sheet1, so the macro needs to be dynamic to catch that. The data in Sheet3 will always remain, and the macro will add the updated data below the old data in Sheet3.

FC_Macro_Sample.xlsm

View 8 Replies View Related

Create Groups In Pivot Table Using VBA

Jan 26, 2012

I regularly build a pivot table using VBA. I now want to group countries into regions within the pivot table, and I want to automate that using vba.

For simplicity, assume I have the countries Germany, Netherlands, Belgium, Luxembourg, Norway and Sweden; and I want to create the Groups BeNeLux and Scandinavia. (In reality, I have 150 countries, one group of 10 countries, 2 countries I want to show individually, and the rest of the world I want to group together)

I know I could select the cells using something like cells(d2:f2).group, but that seems wrong....

I have attached a file showing how far I can get with vba and where i want to get.

I have also tried things like ".DataRange.cells(2).group by:=3" but that never led to anything....

grouping reqs.xls

View 2 Replies View Related

Pivot Tables - Create New Fields On The Fly?

Feb 1, 2010

it's possible to create new fields (variables/columns) on the fly (without adding them to the original data table).

For this example, assume I have a column for:
job code estimated hours
job code actual hours
total estimated hours
total actual hours

Excel has made it easy to run averages or sums for any of those columns, but what if I want to see what the average proportion for job code estimated hours/ total estimated hours? Is there an easy way to do it with pivot tables without adding a column to my database? I'm working in Excel 2007, my data table size is approximately 100 columns by 200 rows.

View 2 Replies View Related

Create List From Pivot Table

Feb 24, 2010

I'm trying to create what is essentially a report card for our staff. I have all the data in a pivot table and then I am using 'GETPIVOTDATA's in the report template to extract the information, linking the sheets via a cell that contains the staff members name. Easy enough. However for reasons of efficiency and practicality I would like to be able to select the names from a drop down list on the sheet rather than having to type it in manually or maintaining a separate sheet for everyone. The operators will change from month to month and there are approximately 90 staff at any given point in time that will need to be reported on so it really needs to be sourced from the pivot data.

View 7 Replies View Related

Create Pivot Table From Different Workbooks?

Jun 17, 2014

For example...

I have data for monday.. Tueday ..Wednesday as individual excel

All the excel have same column names and dynamic values.

Is there a way i can create one pivot with different excel as source

View 1 Replies View Related

Create Own Formula In Pivot Table

Jul 25, 2006

Another question about pivot tables. In Excel it is possible to show different kinds of information in a pivot table like sum, total, min, max, average and so on. I want to create my own formulas in my pivots. Is this possible and if so how?

View 7 Replies View Related

Create Formula In Pivot Table

Jul 28, 2006

I have two questions about dealing with formulas in pivot tables and how to make them dynamic. First let me give you some further background.

My database countains the following variables: Country, Company, Period, Product, Category and Sales. Out of this database i created a pivottable which sums the total sales amount for each company in every period. Further selection on country and category is possible in this pivot table. See my attached file!

I want to express the sales of each company as a percentage of the total sales in that period. For example for company A in period 1 their total sales was (929/3172) 29,3% of the total market sales. Which formula do i have to use in my pivot table to express company's market shares?

Further my pivot table can be specified more detailed by country and category. I want to be able to select on country and category in such a way that the company sales are still expressed as a percentage of the market sales. In other words how can i make my pivot table dynamic?

View 6 Replies View Related

How To Create Dynamic Pivot Table Title

Jun 7, 2014

I have a pivot table without report filter and I set insert page break after one of my selected row labels.

I also would like when I print, these row Labels become the title of these pages at the same time.

Actual File : Untitled.png

However I would like when I click on print or save as pdf will print all pages as one file and each Center that I have set page break for, in separate page and add that specific center as its title:

Attachments for more details:

test_Page_1.jpg
test_Page_2.jpg
test_Page_3.jpg
test_Page_4.jpg

View 4 Replies View Related

Elegant Way To Create Multiple Pivot Table?

Jun 11, 2014

I am currently trying to create a multiple pivot tables in one sheet. The current formula to make a single pivot table that i am using is

Formula:

[Code]....

The current problem i have is... i need to Dim PT01 as pivottable, Dim PT02 as pivottable, Dim PT03 as pivottable and so on.... Repetition is not good!

and secondly,the total pivot table is not constant each week. During busy week, i need to create 8 pivot table and in a slow week, it can go down to 5.

See below of my current formula...

[Code] ....

How to create pivot table in a better way?

View 1 Replies View Related

Create Pivot Table In Hidden Sheet

Mar 18, 2009

I'm getting a 1004 run-time error when creating a pivot table.

I believe this happens because I'm creating it in a hidden sheet. When I unhide it no errors occur.

View 2 Replies View Related

Create Pivot Table For Each File In Folder?

Apr 5, 2012

I have the following code that will open each file in a folder and run code on it. I'm trying to write code that will create a pivot table on each of the opned files...but cannot get past opening the file...

So I had built the vba code into a specific workbook so I could just drop that workbook into any folder I wanted to run code on files to and depending on the name of the file it would run different type of code. The problem has something to do with using "activesheet" for the pivot table wizard. It just doesn't like it and gives me a application 1004 error.

any way I can modify the activesheet so it will make a pivot of the newly opened file? I think what it is trying to do is make a pivot of the blank workbook that the code resides in

Sub filelooper()
MyDir = ActiveWorkbook.Path ' current path
Dim MyFile As String

[Code].....

View 1 Replies View Related

Excel 2010 :: Create Pivot Table VBA

Nov 26, 2013

I'm trying to create a pivot in vba. I can record what I have done but if I run that recorded code, it returns an error "Invalid call procedure or argument".

Code:
ActiveSheet.PivotTableWizard SourceType:=xlDatabase, _
SourceData:=Sheets("Raw Data").Range("A1:AG" & Z), _
TableDestination:=Range("A3"), _

[Code].....

View 1 Replies View Related

Combine Workbooks And Create Pivot Table

May 4, 2014

I have 16 different workbooks for different regions of my company. Each workbook has one worksheet (sheet named each region name), and all workbooks are formatted same regarding column names. Ultimately, I would like to combine all workbooks into one summary workbook where I can build a pivot table and pull out various data. Do you think this method is the best way to do what I am trying to do? I am very novice when it comes to VBA. I have written the code below, however, it is not working.

Code:
Sub GetSheets()
Path = "C:UsersDanielleDesktopWorksheets"
Filename = Dir(Path & "*.xls")
Do While Filename ""
Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
For Each Sheet In ActiveWorkbook.Sheets
Sheet.Copy After:=ThisWorkbook.Sheets(1)
Next Sheet
Workbooks(Filename).Close
Filename = Dir()
Loop
End Sub

View 8 Replies View Related

Merge 2 Tabs Into 1 Spreadsheet To Create Pivot Table?

Jul 9, 2014

I would like to combine 2 tabs into one spreadsheet. I was not able to do so, because it exceeds the max rows allowed in excel. I have installed powerpivots but not sure how to combine data using powerpivots.

View 3 Replies View Related

Determine The Source Data That Was Used To Create The Pivot Table?

Sep 7, 2009

Given a pivot table, is there any way that I can determine the source data that was used to create the pivot table?

I suspect that the pivot table was created using only part of the data, but I'm not sure.

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved