VBA PivotTable Field selection Excel - excel

How do you in VBA change the field selected in rows of your pivot table?
For example, I have a pivot table that has a rows dates field. I want to select a different rows field that available via VBA.

Related

Listing the filtered items in excel

Excel, Windows 10
Say I built a pivot table in excel. The issue I have is that when I select multiple items in the pivot table filter, I can only see (Multiple Items) in the cell pertaining to the pivot table filter.
--> I would like to be able to have a cell that would contain a list of all the items that were selected in that filter for summary purpose.
Is there a way to do that in excel?

VBA excel modifying fields in an existing pivot table

I am using vba excel and I am opening an existing workbook and sheet with a pivot table in it and I need to add a field to the pivot table so that I can access data on the sheet that is not currently there. When I give focus to the pivot table on the right hand side a PivotTable Fields box pops up with a lists of different fields it can show. I need to add one of those fields because it is not currently checked.

Filter Pivot in Report Filter for a range of values

I have the following issue. I have large dataset with product codes, dates at which they are shipped and their tranport method.
I would like to create a pivot of the product code on the left and their transport method on the top. But as variable I would the pivot to only present a range of dates. These dates are presented in the form yyyyww. (example: from 201420 to 201505).
I have a column where each of the individual year and weeknumber as presented, so they could be looked up from there. This also allows it to be a variable.
How can I get this pivot to present this information between a date range?
In Excel 2010 and later you can insert a slicer for any field in the data source and click the values in the slicer that you want to include in the pivot table. Shift click to select contiguous slicer values, Ctrl-click to pick non-contiguous slicer items.
As an alternative to slicers, you can drag the desired filter columns into the filter pane.
The screenshot shows the column names in the filter pane and how the filters appear above the pivot table. It also shows slicers to the right of the pivot table. A pivot table in Excel 2010 and later can have both filters and slicers. Earlier versions can only have filters.
The following screenshot shows what happens when values have been clicked on the slicers. These selected slicer values are mirrored in the filter settings (and vice versa). So, a slicer is just a user-friendly way to select one or more filters for the pivot table.
Please note that you would normally only use one method: either slicer OR filters. Choose the one that you like most.

Use Excel pivot table as data source for another Pivot Table

I have a Pivot table in excel that is using a raw table as its data source. This pivot table is doing a bunch of grouping and summing of rows.
I'd like to now use the result of this new pivot table as the data source for a new pivot table which will further modify this data.
Is this possible with excel? I suppose you could call it 'nested pivot tables'
Make your first pivot table.
Select the first top left cell.
Create a range name using offset:
OFFSET(Sheet1!$A$3,0,0,COUNTA(Sheet1!$A:$A)-1,COUNTA(Sheet1!$3:$3))
Make your second pivot with your range name as source of data using F3.
If you change number of rows or columns from your first pivot, your second pivot will be update after refreshing pivot
GFGDT
In a new sheet (where you want to create a new pivot table) press the key combination (Alt+D+P). In the list of data source options choose "Microsoft Excel list of database". Click Next and select the pivot table that you want to use as a source (select starting with the actual headers of the fields). I assume that this range is rather static and if you refresh the source pivot and it changes it's size you would have to re-size the range as well. Hope this helps.
I guess your end goal is to show Distinct (unique) values inside your original Pivot table.
For example you could have data set with
OrderNumber, OrderDate, OrderItem, orderQty
First pivot table will show you OrderDate and sum of OrderQty and you probably want to see Count of unique orders in the same Pivot.
You woudln't be able to do so within standard pivot table
If you want to do it, you would need Office 2016 (or perhaps pover Pivot might work).
In office 2016 select your data > Insert > Pivot Table > choose tick "Add this data to the Data Model"
After that, you would be able to select grouping method as Distinct (Count)
As suggested you can change the pivot table content and paste as values.
But if you want to change the values dynamically the easiest way I found is
Go To Insert->create pivot table
Now in the dialog box in the input data field select the cells of your previous pivot table.
You have to convert the pivot to values first before you can do that:
Remove the subtotals
Repeat the row items
Copy / Paste values
Insert a new pivot table
As #nutsch implies, Excel won't do what you need directly, so you have to copy your data from the pivot table to somewhere else first. Rather than using copy and then paste values, however, a better way for many purposes is to create some hidden columns or a whole hidden sheet that copies values using simple formulae. The copy-paste approach isn't very useful when the original pivot table gets refreshed.
For instance, if Sheet1 contains the original pivot table, then:
Create Sheet2 and put =Sheet1!A1 into Sheet2!A1
Copy that formula around as many cells in Sheet2 as required to match the size of the original pivot table.
Assuming that the original pivot table could change size whenever it is refreshed, you could copy the formula in Sheet2 to cover the whole of the potential area the original pivot table could ever take. That will put lots of zeros in cells where the original cells are currently empty, but you could avoid that by using the formula =IF(Sheet1!A1="","",Sheet1!A1) instead.
Create your new pivot table based on a range within Sheet2, then hide Sheet2.
Personally, I got around this in a slightly different way - I had a pivot table querying an SQL server source and I was using the timeline slicer to restrict the results to a date range - I then wanted to summarise the pivot results in another table.
I selected the 'source' pivot table and created a named range called 'SourcePivotData'.
Create your summary pivot tables using the named range as a source.
In the worksheet events for the source pivot table, I put the following code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
'Update the address of the named range
ThisWorkbook.Names("SourcePivotData").RefersTo = "='" & Target.TableRange1.Worksheet.Name & "'!" & Target.TableRange1.AddressLocal
'Refresh any pivot tables that use this as a source
Dim pt As PivotTable
Application.DisplayAlerts = False
For Each pt In Sheet2.PivotTables
pt.PivotCache.Refresh
Next pt
Application.DisplayAlerts = True
End Sub
Works nicely for me! :)
here is how I've done this before.
put a dummy column "X" off to the right of your source pivot table.
click in that cell and start your pivot table.
once the dialogue box pops up you can edit the data range to include your pivot table.
this may require you to Refresh the source table first and then refresh your secondary pivot table...or do refresh all twice
I love the offset option -- i had to create a range called that first and did a -3 instead of a -1. Then used that new range for my new pivot table. Now when the first pivot changes, the second will pickup the new rows (or less rows)...

Can I use a cell containing a date to reference for multiple Pivot Tables in Excel?

I am using Excel 2007 & about 20 pivot charts/graphs which reference the same table of data in Excel. I change the data daily, copy and pasting the data from another source. Can I somehow create a reference cell that contains a date for the pivot tables so that I don’t have to change the dates on every graph drop down every day? Another solution would be to have all the graphs reference the same data section on the pivot table, is that possible?
as far as the data range of a pivot table is concerned, you can base multiple Pivots on the same data range.
define the 1st Pivot Table by selecting the data range
for Pivot Tables 2..n select the 1st table as the data source
for Pivot charts - if you just want to display the actual date in a title
create the Pivot Chart
click the title and enter a formula making use of your "dynamic title cell" in same way as in sheets (e.g. =Sheet1!$A$1)
at least in Excel 2003 it's not possible to do this in a Pivot Chart Title: ="Stat for " & Sheet1!$A$1; so as a workaround you do this in cell A1 of Sheet1

Resources