Reputation: 37
I want to compare my variable with a pivot field.
Here's what I got:
Dim ptField As PivotField
Dim Table As PivotTable
Dim Field As String
Dim Pos As Integer
Dim ptr_Field as String
Set Table = Sheets("Sheet1").PivotTables(1)
Set ptr_Field = "Value1"
For Each Stat In Table.PivotFields
If ptr_Field.Name = Stat Then
MsgBox "True"
End If
Next
But it doesn't work.
Can someone help me please?
Upvotes: 0
Views: 47
Reputation: 181
You have defined ptField as PivotField but you never reference it and instead refer to Stat which you have not defined at all. You have also defined Field and Pos which never get used.
Also, you are trying to reference ptf_Field.Name which would imply that ptf_Field was an object with a property called Name when in fact it is defined as a String. Try:
For Each ptField in Table.PivotFields
If ptf_Field = ptField.Value Then
MsgBox "True"
End If
Next
Upvotes: 2