vendredi 24 juin 2016

IF Statement Excel VBA

strTemp = ActiveSheet.PivotTables("BreakCon").PivotFields("Service Type").PivotItems("International Data")
        If Err = 0 Then FieldExists = True Else FieldExists = False
        If FieldExists = True Then
          With ActiveSheet.PivotTables("BreakCon").PivotFields("Service Type")
            .PivotItems("International Data").Visible = False
            .PivotItems("Non Contracted").Visible = False
        ElseIf FieldExists = False Then
         With ActiveSheet.PivotTables("BreakCon").PivotFields("Service Type")
            .PivotItems("Non Contracted").Visible = False

        Else
            MsgBox ("Error")
        End If

Occasionally the data passing through the code has "International Data" however occasionally it doesn't so i added this If statement to try and check whether "International Data" is in the Pivot Table and if not then go to the next if statement. Can anyone see an issue with this code? i have tried all of the ways i know but have hit a brickwall! Cheers!

Aucun commentaire:

Enregistrer un commentaire