View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Passing Variable Number of Arguments to a Sub

..getpivottable isn't looking for one string. So the join() won't work.

I was hoping that I could pass an array to that function, but it didn't work for
me.

I think the way I'd approach it is to keep track of how many parms I want to use
and then base the calls on that:

select case myParms
'for example
case is = 3
GPD3 = rPivotTable.PivotTable.GetPivotData(parm1, parm2, parm3)
case is = 5
GPD3 = rPivotTable.PivotTable _
.GetPivotData(parm1, parm2, parm3, parm4, parm5)
'etc
end select

But there might be an easier way--but I don't know it.



blatham wrote:

Thanks for that. What I'm really trying to do is construct the
arguments for the GetPivotData method in a function. I want the
function to accept the same arguments as the regular worksheet function
but my version will be able to handle Grand Totals for a particular
field. The regular version doesn't do this - you have to include lots
of different IF and GETPIVOTDATA functions depending on what you are
trying to retrieve. Hope I'm making sense! This is what I have at the
moment:

Function GPD3(sDataField As String, rPivotTable As Range, ParamArray
FieldValPairs())

Dim sArgs As Variant
Dim i As Integer
Dim j As Integer
j = 0
sArgs(j) = sDataField
For i = 0 To UBound(FieldValPairs()) Step 2
If FieldValPairs(i + 1) < "Grand Total" Then
sArgs(j) = FieldValPairs(i)
sArgs(j + 1) = FieldValPairs(i + 1)
j = j + 2
End If
Next i

GPD3 = rPivotTable.PivotTable.GetPivotData(Join(sArgs, ","))

End Function

--
blatham
------------------------------------------------------------------------
blatham's Profile: http://www.excelforum.com/member.php...o&userid=19441
View this thread: http://www.excelforum.com/showthread...hreadid=491996


--

Dave Peterson