Consulting

Results 1 to 7 of 7

Thread: Selecting Multiple Items in a Pivotfield, Hoping to be able to Toggle with a Hotkey

  1. #1
    VBAX Regular
    Joined
    Sep 2013
    Posts
    37
    Location

    Exclamation Selecting Multiple Items in a Pivotfield, Hoping to be able to Toggle with a Hotkey

    Sub esis()
    Dim pf As PivotField
    Dim pi As PivotItem
    'Application.ScreenUpdating = False

    Set pf = ActiveSheet.PivotTables("PivotTable4").PivotFields("TRAN_GROUP")
    With pf

    For Each pi In pf.PivotItems

    If pi.TRAN_GROUP = "ESIS" _
    Or pi.TRAN_GROUP = "ESISFF" _
    Or pi.TRAN_GROUP = "ESISFFC" _
    Or pi.TRAN_GROUP = "ESISMN" _
    Or pi.TRAN_GROUP = "PMIGEN1ESIS" Then
    pi.Visible = True
    Else
    pi.Visible = False

    End If
    Next pi
    End With
    'Application.ScreenUpdating = True
    End Sub

    this is what I have and for some reason I cant get it to work. I get the error 438 object does not support this property or method.

    can anyone help?

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Pivotitems do not have a TRAN_GROUP property. Try:

    [vba]Select Case pi.Caption
    Case "ESIS", "ESISFF", "ESISFFC", "ESISMN", "PMIGEN1ESIS"
    pi.Visible = True
    case Else
    pi.Visible = False
    End Select
    [/vba]
    Be as you wish to seem

  3. #3
    VBAX Regular
    Joined
    Sep 2013
    Posts
    37
    Location

    Exclamation

    Quote Originally Posted by Aflatoon View Post
    Pivotitems do not have a TRAN_GROUP property. Try:

    [vba]Select Case pi.Caption
    Case "ESIS", "ESISFF", "ESISFFC", "ESISMN", "PMIGEN1ESIS"
    pi.Visible = True
    case Else
    pi.Visible = False
    End Select
    [/vba]
    Sub esis2()

    Dim pf As PivotField
    Dim pi As PivotItem
    Application.ScreenUpdating = False

    Set pf = ActiveSheet.PivotTables("PivotTable4").PivotFields("TRAN_GROUP")
    With pf
    Select Case pi.Caption
    Case "ESIS", "ESISFF", "ESISFFC", "ESISMN", "PMIGEN1ESIS"
    pi.Visible = True
    Case Else
    pi.Visible = False
    End Select
    End With

    End Sub

    still not working object variable or with block variable not set. I really appreciate the help!!

  4. #4
    VBAX Regular
    Joined
    Sep 2013
    Posts
    37
    Location
    I am in 2007 also if that makes a difference.

  5. #5
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    You shouldn't have removed the loop:
    [vba]Sub esis()
    Dim pf As PivotField
    Dim pi As PivotItem
    'Application.ScreenUpdating = False

    Set pf = ActiveSheet.PivotTables("PivotTable4").PivotFields("TRAN_GROUP")
    With pf

    For Each pi In pf.PivotItems

    Select Case pi.Caption
    Case "ESIS", "ESISFF", "ESISFFC", "ESISMN", "PMIGEN1ESIS"
    pi.Visible = True
    Case Else
    pi.Visible = False
    End Select
    Next pi
    End With
    'Application.ScreenUpdating = True
    End Sub[/vba]
    Be as you wish to seem

  6. #6
    VBAX Regular
    Joined
    Sep 2013
    Posts
    37
    Location
    Thanks so much!!

    you = VBA super hero

  7. #7
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Not really, but thank you!
    Be as you wish to seem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •