当我尝试引用数据透视表中的特定单元格引用时遇到困难。
Dim SelectionNum As Integer
LastRow = ActiveSheet.PivotTables("CMAPivot").TableRange2.Rows.Count
SelectionNum = WorksheetFunction.RandBetween(4, LastRow)
MsgBox(GETPIVOTDATA("CLM_NR",CMAPivot!$A$[SelectionNum])) ' this is the line I get a syntax error on
我也尝试过:
MsgBox(GETPIVOTDATA("CLM_NR",$A$[SelectionNum])) as well as
MsgBox(GETPIVOTDATA("CLM_NR","CMAPivot"!$A$[SelectionNum]))
无论如何,我的单元格引用 $A$[SelectionNum] 出现语法错误(我也尝试过不带括号)
我基本上是尝试随机选择一个索赔编号以进行审计。一旦我成功引用 CLM_NR,我就会将该值写入电子表格上的单元格。
提前感谢您的帮助!
GETPIVOTDATA
用于获取数据透视表中数据体区域的数据。4
)可能会有所不同。Option Explicit
Sub demo()
Dim SelectionNum As Long
Dim LastRow As Long, RowCnt As Long
Dim ColRng As Range
With ActiveSheet.PivotTables("CMAPivot")
Set ColRng = .TableRange2.Columns(1)
RowCnt = ColRng.Cells.Count - .DataBodyRange.Rows.Count
End With
SelectionNum = WorksheetFunction.RandBetween(RowCnt + 1, ColRng.Cells.Count)
MsgBox ColRng.Cells(SelectionNum)
End Sub