sourabh_ajmera
New Member
- Joined
- Jul 17, 2014
- Messages
- 36
I want to find out if a particular field, say a month from Jan-14 to Dec-14, exists in 'pivot field list' before adding it to the pivot table?
can you please help me out on this as I have tried couple of things but doesnt work.
Here is my code:
This always returns false. Ain't able to figure out another way. Please Help
Thanks in advance!!
can you please help me out on this as I have tried couple of things but doesnt work.
Here is my code:
Code:
Sub Test()
If (FieldItemExists("Feb - 14") = True) Then
ActiveSheet.PivotTables("usdPivotTable").AddDataField ActiveSheet.PivotTables( _
"usdPivotTable").PivotFields("Feb-14"), "Sum of Feb-14", xlSum
End If
End Sub
Function FieldItemExists(strName As String) As Boolean
Dim strTemp As String
On Error Resume Next
strTemp = ActiveSheet.PivotTables("usdPivotTable").PivotFields(strName)
If Err = 0 Then
FieldItemExists = True
Else
FieldItemExists = False
End If
End Function
This always returns false. Ain't able to figure out another way. Please Help
Thanks in advance!!
Last edited: