• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro not working

Hi All,


I created a macro but it does not work, attached is the code.


What is supposed to do from a master dropdown box is syncronized the other drown down boxes, what it cannot do is deselect the previous selection and select a new value.


the eror message reads as follows. run-time error 1004


application-defined or object-defined error, please help!!!


Sub mastpvt()

'

' mastpvt Macro

'


'

ActiveSheet.PivotTables("pvt1").PivotFields("NICKNAME").CurrentPage = Range("E1").Text


With ActiveSheet.PivotTables("pvt1").PivotFields("NICKNAME")

.PivotItems("MAY").Visible = True

.PivotItems("ADDAMS").Visible = False

End With

ActiveSheet.PivotTables("pvt2").PivotFields("NICKNAME").CurrentPage = Range("E1").Text

With ActiveSheet.PivotTables("pvt2").PivotFields("NICKNAME")

.PivotItems("MAY").Visible = True

.PivotItems("ADDAMS").Visible = False

End With

ActiveSheet.PivotTables("pvt3").PivotFields("NICKNAME").CurrentPage = Range("E1").Text

With ActiveSheet.PivotTables("pvt3").PivotFields("NICKNAME")

.PivotItems("MAY").Visible = True

.PivotItems("ADDAMS").Visible = False

End With

ActiveSheet.PivotTables("pvt4").PivotFields("NICKNAME").CurrentPage = Range("E1").Text

With ActiveSheet.PivotTables("pvt4").PivotFields("NICKNAME")

.PivotItems("MAY").Visible = True

.PivotItems("ADDAMS").Visible = False

End With
 
Dgavilanes


I would add a single line after each PT update

[pre]
Code:
'Application.CutCopyMode = False
like:

Sub mastpvt()
'
' mastpvt Macro
'

ActiveSheet.PivotTables("pvt1").PivotFields("NICKNAME").CurrentPage = Range("E1").Text
With ActiveSheet.PivotTables("pvt1").PivotFields("NICKNAME")
.PivotItems("MAY").Visible = True
.PivotItems("ADDAMS").Visible = False
End With
Application.CutCopyMode = False

ActiveSheet.PivotTables("pvt2").PivotFields("NICKNAME").CurrentPage = Range("E1").Text
With ActiveSheet.PivotTables("pvt2").PivotFields("NICKNAME")
.PivotItems("MAY").Visible = True
.PivotItems("ADDAMS").Visible = False
End With
Application.CutCopyMode = False

ActiveSheet.PivotTables("pvt3").PivotFields("NICKNAME").CurrentPage = Range("E1").Text
With ActiveSheet.PivotTables("pvt3").PivotFields("NICKNAME")
.PivotItems("MAY").Visible = True
.PivotItems("ADDAMS").Visible = False
End With
Application.CutCopyMode = False

ActiveSheet.PivotTables("pvt4").PivotFields("NICKNAME").CurrentPage = Range("E1").Text
With ActiveSheet.PivotTables("pvt4").PivotFields("NICKNAME")
.PivotItems("MAY").Visible = True
.PivotItems("ADDAMS").Visible = False
End With
Application.CutCopyMode = False
[/pre]
 
Dennis


I think this will do it for you

Before running this select each Page Field Nickname and change it so that Select Muliple Items ISN'T ticked

[pre]
Code:
Sub mastpvt()
'
' mastpvt Macro
'
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = True

PgField = Range("G1")
Sheets("Master").PivotTables("pvt1").PivotFields("Nickname").CurrentPage = PgField
Sheets("Master").PivotTables("pvt2").PivotFields("Nickname").CurrentPage = PgField
Sheets("Master").PivotTables("pvt3").PivotFields("Nickname").CurrentPage = PgField
Sheets("Master").PivotTables("pvt4").PivotFields("Nickname").CurrentPage = PgField

Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub
[/pre]
 
Did you select each Pivot Table, Page Field "Nickname" and change it so that Select Muliple Items ISN'T ticked?


Here is your file: https://www.dropbox.com/s/w766r5hshxam96d/test%20template_demo_isat.xlsm


When you say it isn't working, please elaborate?

Also what version of Excel are you using ?
 
Hi Hui,


Just for curiosity..

* The code provided in post#36792 and file provided in post#36814, both are same.. except variable name (previously PgField and now SPgField2)..

Then why previous code got error and second was working..

I hope PgField is not even a Keyword..


Thanks..

Deb


EDIT:


Sorry IAN, I got it..

First File is with ....EnableMultipleItem = True

and Second File is with ....EnableMultipleItem = False
 
Both should be

EnableMultipleItem = False


I just cleaned up the code in the post


Does it work for you Deb ?
 
Ian,


Yes Its working perfectly..:)


One silly Question..

How can I set value for SPgField2 by

Code:
SPgField2 = Application.Caller.???
Function..


Regards,

Deb
 
Hui,


I do not know what to say other than ""THANK YOU GUYS"" !!! you guys are awesome.


if you ever come this way (Chicago)I show you this great city, you have a friend her


regards, Dennis
 
Back
Top