在GETPIVOTDATA函数中为参数添加字符串

时间:2016-04-19 01:39:21

标签: excel excel-vba vba

我真的希望有人能解决这个问题。我有一个GETPIVOTDATA函数运行良好,但我想添加一个已经格式化的字符串,以添加到GETPIVOTDATA。以下是GETPIVOTDATA函数的示例:

=GETPIVOTDATA("Sum of "&$O$62,$B$65,"Class",B69,"Scenario",$C$67,"Capital/Operating",$T$64)

这是我想要添加到GETPIVOTDATA函数末尾的字符串。

"Project","(C0000000046) Professional Development","Task","(300) Certifications"

项目和任务是字段,“(C0000000046)专业开发”和“(300)认证”是我要在评估之前添加到GETPIVOTDATA函数的项目。

有谁知道如何实现这一目标?

已更新

Here是一个示例文件。

1 个答案:

答案 0 :(得分:0)

如果您只想将新参数添加到现有公式中:

=GETPIVOTDATA("Sum of " & $O$62, $B$65,"Class", B69, "Scenario", $C$67, "Capital/Operating", $T$64, _
"Project","(C0000000046) Professional Development","Task","(300) Certifications")

这里有关于拆分的建议:

DIM strInput as String
DIM strSplit() as String
DIM strGetPivot as String
DIM intCount as Integer
strInput = "Project,(C0000000046) Professional Development,Task,(300) Certifications"
strGetPivot = "=GETPIVOTDATA(""Sum of "" & $O$62, $B$65,""Class"", B69, ""Scenario"", $C$67, ""Capital/Operating"", $T$64,"
strSplit = Split(strInput, ",")
For intCount  = 0 to UBOUND(strSplit) - 1
   strGetPivot = strGetPivot & ", """ & Trim(strSplit(intCount)) & """
Next
strGetPivot = strGetPivot & ")"