Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XL 2002 Change Event 2

Status
Not open for further replies.

vaneagle

Technical User
Apr 23, 2003
71
0
0
AU
HI All,

Not sure how to go about this. I have a pivot table in a worksheet. IF a user selects a page selection I need an an event to happen. The cell that this sits in is B4.

The code I have is:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Target.ActiveSheet.PivotTables("PivotTable9").PivotFields("Trading Dept").CurrentPage _
        = "Total"
End Sub

Perhaps I think I am not using this correctly. Basically if the User changes cell B4 to the option "All", then I want the code to correct their selection so that "Total" instead is selected. If they choose anything else apart from "All" then nothing happens with the code. Does this make sense?

thanks in advance,

vaneagle
 
Take a look at the Intersect method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
The problem is that the TARGET when a pivottable is changed is not necessarily the page field - I think you get a range of cells that covers the entire pivot table - as PHV says - look into the intersect method - you can also test what "Target" is by using

msgbox Target.address

Rgds, Geoff

Never test the depth of water with both feet

Help us to help you by reading FAQ222-2244 before you ask a question
 
Thanks Guys...

I'll do a search on the intersect method and test the 'Target' at the same time with your suggestion Geoff.

Thanks,
vaneagle
 
I got it to work with the following:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Worksheets(3).Activate
    Set isect = Application.Intersect(Range("b4"), Range("b4"))
    If isect Is Nothing Then
        MsgBox "Ranges do not intersect"
    Else
        If ActiveSheet.PivotTables("PivotTable9").PivotFields("Trad Dept").CurrentPage = "(All)" Then
        
        ActiveSheet.PivotTables("PivotTable9").PivotFields("Trad Dept").CurrentPage = "Total"
MsgBox Target.Address        
        End If
    End If
  End Sub

thanks again for your suggestions..
btw with
Code:
msgbox target address
it indeed selects the entire pivot table.

Have a star guys!

regards,

vaneagle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top