Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Newbie code not working

I'm trying to use one pivot table filter to activate both pivot tables on one
sheet in Excel 2007. Code doesn't seem to be working. Any help would be
greatly appreciated.


Private Sub Worksheet_Calculated()


Dim MvPivotPageValue As Variant

Dim Pt As PivotTable 'main pivot table
Dim Pt1 As PivotTable ' 2nd pivot table
Dim WsOther As Worksheet ' name of worksheet
Dim strField As String ' report filter name

Set WsOther = Sheets("Division Summary1")
Set Pt = PVT1
Set Pt1 = WS.Other.PVT2
Set strField = "Fiscal Calendar"

If LCase(Pt.PivotFields("Fiscal Calendar").CurrentPage) <
LCase(MvPivotPageValue) Then
Application.EnableEvents = False
Pt.RefreshTable
MvPivotPageValue = Pt.PivotFields(strField).CurrentPage
Pt1.PageFields(strField).CurrentPage = MvPivotValue
Application.EnableEvents = True
End If

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Newbie code not working

Hi,

Whenever you are requesting help, and your code isn't working, it is best if
you state why your code is not working (I know that might sound stupid, but
I'll explain :) ). Sometimes your code may be doing something other than what
you expect, in which case try to explain what you expect and what actually
happens. Sometimes nothing may happen at all, but this isn't likely. Finally,
you may be getting errors, which cause the Debug dialogue.

Having looked at your code I can see some potential problems, but these
might be typos from you putting your code here, or they might be the problem.
Anyway, I'll say what I see and you can see if this helps.

Firstly, you are setting the first pivottable, Pt using

Set Pt = PVT1

I assume PVT1 is the name of the pivottable. Unless PVT1 is an object
variable within your code that already refers to a pivottable, you will
probably get an error here.

To set a pivottable variable, use (and using your sheet variable)

Set Pt = WsOther.Pivottables("PVT1")

When you set Pt1 you have a period in the sheet name. Use above, so:

Set Pt1 = WsOther.Pivottables("PVT2")

Towards the end of your code you use:

Pt1.PageFields(strField).CurrentPage = MvPivotValue

Check your variables carefully, this should be MvPivotPageValue.

At one point you refer to a pivotfield by name ("Fiscal Calendar"), but the
rest of the time you use strField, I would amend this to be consistent,
unless you did this intentionally.

Anyway, these suggestions should hopefully get you a step further. If you
are still having problems then let me know.

Good luck,

Sean.
--
(please remember to click yes if replies you receive are helpful to you)


"pkern" wrote:

I'm trying to use one pivot table filter to activate both pivot tables on one
sheet in Excel 2007. Code doesn't seem to be working. Any help would be
greatly appreciated.


Private Sub Worksheet_Calculated()


Dim MvPivotPageValue As Variant

Dim Pt As PivotTable 'main pivot table
Dim Pt1 As PivotTable ' 2nd pivot table
Dim WsOther As Worksheet ' name of worksheet
Dim strField As String ' report filter name

Set WsOther = Sheets("Division Summary1")
Set Pt = PVT1
Set Pt1 = WS.Other.PVT2
Set strField = "Fiscal Calendar"

If LCase(Pt.PivotFields("Fiscal Calendar").CurrentPage) <
LCase(MvPivotPageValue) Then
Application.EnableEvents = False
Pt.RefreshTable
MvPivotPageValue = Pt.PivotFields(strField).CurrentPage
Pt1.PageFields(strField).CurrentPage = MvPivotValue
Application.EnableEvents = True
End If

End Sub


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie floundering in the VBA code Baloo Excel Programming 1 January 17th 08 06:44 PM
Newbie needs assistance with VBA code SherryW Excel Programming 6 October 16th 07 08:16 PM
If-Then in ComboBox_Change..... (VB Code Newbie) JustBreathe Excel Programming 1 March 28th 07 06:38 PM
Newbie : How to sum cells via VBA code. Rich[_16_] Excel Programming 5 February 24th 04 02:30 AM


All times are GMT +1. The time now is 02:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"