Hi Experts<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
I have setting up a customer Excel function in VBA that gets data from a Pivot table.<o></o>
The purpose of the function is to return the value from a pivot table like Excel GETPIVOTDATA function but with a special condition if the return value is #VALUE. If I do this with Excel only I have to nest the function into an IF statement that check is the return value is and error (e.g #VALUE). If it is then the return value should be Zero.<o></o>
This is what the Excel function looks like:<o></o>
=IF(ISERROR(GETPIVOTDATA("_YTD",Pivot!$A$3,"Account","PL1000","Period","1012","Actuality","AC","Company","00031","Currency","NZD"))= True, 0, GETPIVOTDATA("_YTD",Pivot!$A$3,"Account","PL1000","Period","1012","Actuality","AC","Company","00031","Currency","NZD"))<o></o>
I have am trying to include in the function the IF statement logic so the users don’t have to build a long and complex function. <o></o>
The problem I have is that the return result is #VALUE if the data is not in the Pivot. I cannot get the function to see this error and return 0.<o></o>
The function is successful if all the parameters are met.<o></o>
This is my function code:<o></o>
Private Function ccufGetValx(Period As String, Optional Par2 As String, Optional YTD_Mnth As String, Optional Actuality As String, Optional CompCode As String, Optional Structure As String, Optional Par4 As String, Optional ParCurrency As String, Optional AccCode As String, Optional Par5 As String, Optional Par6 As String, Optional Par7 As String, Optional Par8 As String, Optional Par9 As String, Optional CloVer As String, Optional Par10 As String, Optional ConVer As String) As Double
Dim b As Double<o></o>
Dim PT As PivotTable
Set PT = Worksheets("Pivot").PivotTables(1)
'Get the value from the pivot table<o></o>
If IsError((PT.GetPivotData("_YTD", "Account", AccCode, "Period", Period, "Actuality", Actuality, "Company", CompCode, "Currency", ParCurrency).Value)) = True Then<o></o>
b = 0<o></o>
Else<o></o>
b = (PT.GetPivotData("_YTD", "Account", AccCode, "Period", Period, "Actuality", Actuality, "Company", CompCode, "Currency", ParCurrency).Value)<o></o>
End If
ccufGetValx = b
End Function
I have setting up a customer Excel function in VBA that gets data from a Pivot table.<o></o>
The purpose of the function is to return the value from a pivot table like Excel GETPIVOTDATA function but with a special condition if the return value is #VALUE. If I do this with Excel only I have to nest the function into an IF statement that check is the return value is and error (e.g #VALUE). If it is then the return value should be Zero.<o></o>
This is what the Excel function looks like:<o></o>
=IF(ISERROR(GETPIVOTDATA("_YTD",Pivot!$A$3,"Account","PL1000","Period","1012","Actuality","AC","Company","00031","Currency","NZD"))= True, 0, GETPIVOTDATA("_YTD",Pivot!$A$3,"Account","PL1000","Period","1012","Actuality","AC","Company","00031","Currency","NZD"))<o></o>
I have am trying to include in the function the IF statement logic so the users don’t have to build a long and complex function. <o></o>
The problem I have is that the return result is #VALUE if the data is not in the Pivot. I cannot get the function to see this error and return 0.<o></o>
The function is successful if all the parameters are met.<o></o>
This is my function code:<o></o>
Private Function ccufGetValx(Period As String, Optional Par2 As String, Optional YTD_Mnth As String, Optional Actuality As String, Optional CompCode As String, Optional Structure As String, Optional Par4 As String, Optional ParCurrency As String, Optional AccCode As String, Optional Par5 As String, Optional Par6 As String, Optional Par7 As String, Optional Par8 As String, Optional Par9 As String, Optional CloVer As String, Optional Par10 As String, Optional ConVer As String) As Double
Dim b As Double<o></o>
Dim PT As PivotTable
Set PT = Worksheets("Pivot").PivotTables(1)
'Get the value from the pivot table<o></o>
If IsError((PT.GetPivotData("_YTD", "Account", AccCode, "Period", Period, "Actuality", Actuality, "Company", CompCode, "Currency", ParCurrency).Value)) = True Then<o></o>
b = 0<o></o>
Else<o></o>
b = (PT.GetPivotData("_YTD", "Account", AccCode, "Period", Period, "Actuality", Actuality, "Company", CompCode, "Currency", ParCurrency).Value)<o></o>
End If
ccufGetValx = b
End Function