I have this problem that I can't solve, I'm writing an Excel Macro that build up a pivot table taking the data from a table.
When a field in the table is 0 I don't want to perform the calculation of the calculated field and display a blank cell in the pivot table.
my conditional formula is this one:
=IF((field1=0),"",(field1/field2))
Putting this formula into VBA as follows
pt.CalculatedFields.Add Name:="ptfieldname", Formula:="=IF((field1=0),"",(field1/field2))"
display an empty pivot table, when I put the same formula in excel using the "Fields, Items & Set" button in the pivot table option tab goes well...
so I think that the formula is right, but what I have to do to get it permorf well also within the VBA macro?!
thanks in advance
Welcome to SO. I am pretty new here myself, but have found it very useful lately.
Anyway, here is your answer. I found it by using the Macro Recorder to see the exact syntax it uses when creating a calculated field in the pivot table. Hopefully the method of my finding the answer helps you find more answers on your own in the future.
The problem was in the way you referenced the formula in VBA. VBA needs to have actual quotes inside of quotes, so the
=IF((field1=0),"",(field1/field2))
in
pt.CalculatedFields.Add Name:="ptfieldname", Formula:="=IF((field1=0),"",(field1/field2))"
needs to be
=If(field1=0,"""",(field1/field2))
Related
I'm trying to use structured references with Excel tables https://support.microsoft.com/en-us/office/using-structured-references-with-excel-tables-f5ed2452-2337-4f71-bed3-c8ae6d2b276e.
If I copy-paste the formula like =DeptSales[[Sales Person]:[Region]] in a cell, Excel returns an "There's a problem with this formula..." error.
One solution is to choose the Sales Person that the intellisense proposes:
I don't understand why hard-coded Sales Person is not accepted. Could anyone help?
PS: the version of my Excel for Windows:
Why dont you type = in the cell where you are putting the formula, then select the target cells with your mouse? Then it should work correctly.
I dont see the calculations that you want to do? Is it count or sum or something?
Please see my example below. It works fine.
I am not sure if this is too ambitious. Currently I'm generating a bunch of pivot tables through our server (I won't go into detail) but our main stocktaking spreadsheet references these generated pivot tables weekly and pulls their figures through.
i.e using code ='C:\Users\ITS1\Documents\Test\Establishment\190303[Stocktake.xlsx]Data4'!$D$3 which is simple enough - just referencing whatever figure is in that cell on the pivot table.
There is a particular bunch of figures on some pivot tables each week called 'Redemption' which, depending on what other kind of sales an establishment generates, shift to different cells each week. So I can't reference them like other figures which are always fixed to the same cells on every generated pivot table.
Is there a way I can reference the pivot table by the keyword 'Redemption' and take the figure from the cell directly next to it which is the actual figure we need to record?
While this isn't hugely urgent, it would be quite handy. These figures can just be manually entered but just trying out some automation to eliminate my human error :)
If you don't want to have to open the external workbook, this approach might be feasible:
In the external workbook, create a helper sheet that uses a formula to look up the Redemption field value. This could possibly be done with a GetPivotData formula. The exact formula depends on your data and without seeing that I can't write it.
The idea here is that the helper sheet and the location of the cell on the helper sheet does not change. When the pivot table is refreshed, the formula calculates the result.
In the other workbook you can now use an absolute reference to that helper sheet and cell and don't need to open the external file to retrieve the value.
I have an excel sheet that was provided to me to implement a business flow.
I see a formula in a column as below:
=[#[Inventory]]
I understand that this copies data from other column with heading 'Inventory'. But when I try to mimic this on a different sheet for a different column , I don't get any values. I'm I missing something here.
It's a function of structure reference.
# means ThisRow.
You could learn more from:
https://support.office.com/en-us/article/using-structured-references-with-excel-tables-f5ed2452-2337-4f71-bed3-c8ae6d2b276e
The =[#[Inventory]] works only on columns, which are part of Excel Tables, created either from the Ribbon, through Ctrl+T (or through vba):
This style of formula works with Excel listobject tables. The # symbol refers to the current row of the specified column. There's a good intro guide here
I am having issues with extracting pivot table from another worksheet. I believe my syntax is wrong, but after trying several different renditions, nothing is correct.
here is what I have
=Getpivotdata('Other WorkSheet'!$A$1 "Count of SOMETHING", $A$1)
I think my issue is with the absolute cell reference in the direction to the other sheet. However my search for answers has turned up nothing.
What's wrong exactly? You don't need to type in the function, simply click the cell you want and Excel will create the function for you.
I ended up going back to the drawing board as I felt that I wasn't entering the formula in correctly. I should've posted this yesterday but I got tied down into something. The problem was how I was directing the formula to find the pivot table in question. The reference to the other worksheet should have been in the part of the formula that tells excel where the pivot table is. Here is the correct syntax:
=getpivotdata("Count of SOMETHING", 'Other Worksheet'!$A$1)
Basically I had it backwards.
I hope this is a quick and easy question for Excel pros out there.
I'm using the default "Retirement Planner" spreadsheet in MS Excel 2013. I want to make some modifications to the existing formulas, but every time I click on a cell, the formula looks something like:
=IFERROR(Calculations!G39,"")
How do I view the actual formula used to calculate the value of that cell? It seems like this syntax:
Calculations!G39
Abstracts away the underlying formula.
Thanks for the help!
There is a hidden Calculations sheet which you can unhide by right-clicking the Retirement Planner sheet tab and selecting Unhide from the pop-up options.
In cell G39 on the Calculations sheet is a formula =Interest which is reference to a Named Range.
If you go into the Name Manager on the Ribbon Formulas tab you will find that Interest contains a formula:
=IF(PlanYear<=PlanYears,(Calculations!F39*BeforeRetirement*InvestmentReturnPreRetirementPercentage)+(Calculations!F39*AfterRetirement*InvestmentReturnPostRetirementPercentage),NA())