【发布时间】:2018-11-23 11:12:21
【问题描述】:
我有一个 VBA 代码,它创建一个数据透视表,然后根据动态范围找到平均值(因为数据透视表的大小总是在变化)
我想使用 AVERAGEIF 函数而不是平均值,这样我就可以对所有“>0”的值进行平均。我遇到的问题是 Excel 不允许引号内的引号,所以我不能将条件“>0”放在函数中。我当前的代码是:
Sub BuildLaborTable()
'
'This procedure builds the labor table and finds the average of the rows
ActiveWorkbook.ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("Pivot ZP2P").PivotFields("Notif Service product")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("Pivot ZP2P").AddDataField ActiveSheet.PivotTables( _
"Pivot ZP2P").PivotFields("Actual Qty"), "Sum of Actual Qty", xlSum
With ActiveSheet.PivotTables("Pivot ZP2P").PivotFields("Notifctn")
.Orientation = xlColumnField
.Position = 1
End With
Range("A6").Select
Selection.End(xlToRight).Select
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "Average"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "Median"
ActiveCell.Offset(1, -1).Select
ActiveCell.FormulaR1C1 = "=AVERAGE(RC2:RC[-2])"
End Sub
我想使用公式 AVERAGEIF(RC2:RC[-2],">0") ,但问题是这需要引号内的引号,这是不允许的。
【问题讨论】:
-
为什么不允许引号中的引号?
-
@TimWilkinson 因为他这么说,天啊!! /s :)
标签: vba excel excel-formula