Dear all,
I hope you can help me with the following issue, because I'm completely new with VBA code and I'm learning at the moment.
I'm creating a Pivot table in Sheet B based on input from Sheet A. Let's assume I've the following lines.
I have the following code now:
This is for the calculation of the field:
ActiveSheet.PivotTables("ForecastPivotTable").CalculatedFields.Add Name:="WAVG Forecast Price", _
Formula:="=IFERROR(Calculated Finance Forecast/Calculated Sales Forecast,0)"
This is to show the field in the Pivot Table which is created with VBA Code:
With ActiveSheet.PivotTables("ForecastPivotTable").PivotFields("WAVG Forecast Price")
.Orientation = xlDataField
.Function = xlSum
.NumberFormat = "0.00"
The result now is that the WAVG Forecast Price = 6,6. But this is incorrect. I would like to leave out all the lines for the item number with a 0 value in the Total Price and/or in the Total Qty. The result should be (100+200+360)=660 divided by (10+20+30)=60 = 660/60=11.
I hope somebody can help me out to find the correct Formula:= for this. I've tried several things I found on Google, like AVERAGEIFS or SUMPRODUCT, but nothing worked. Probably I made some mistakes.
Thank you very much for your help.
I hope you can help me with the following issue, because I'm completely new with VBA code and I'm learning at the moment.
I'm creating a Pivot table in Sheet B based on input from Sheet A. Let's assume I've the following lines.
Item number | Total Qty | Total Price |
12345 | 10 | 100 |
12345 | 20 | 200 |
12345 | 30 | 360 |
12345 | 40 | 0 |
I have the following code now:
This is for the calculation of the field:
ActiveSheet.PivotTables("ForecastPivotTable").CalculatedFields.Add Name:="WAVG Forecast Price", _
Formula:="=IFERROR(Calculated Finance Forecast/Calculated Sales Forecast,0)"
This is to show the field in the Pivot Table which is created with VBA Code:
With ActiveSheet.PivotTables("ForecastPivotTable").PivotFields("WAVG Forecast Price")
.Orientation = xlDataField
.Function = xlSum
.NumberFormat = "0.00"
The result now is that the WAVG Forecast Price = 6,6. But this is incorrect. I would like to leave out all the lines for the item number with a 0 value in the Total Price and/or in the Total Qty. The result should be (100+200+360)=660 divided by (10+20+30)=60 = 660/60=11.
I hope somebody can help me out to find the correct Formula:= for this. I've tried several things I found on Google, like AVERAGEIFS or SUMPRODUCT, but nothing worked. Probably I made some mistakes.
Thank you very much for your help.