Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default RunTime Error 1004? _Default Property?

Hi All,

I'm writing some code that automatically changes PageField Values in a
PivotTable. On one of them, I get a Run Time Error 1004 "Unable to set the
_Default property of the PivotItem Class".

Does anyone know what this means in this context? Below is a section of code
that I'm using, and it works ok on another field that I am doing it on...

ActiveSheet.PivotTables("PivotTable1").PivotFields ("Wk_Ending").CurrentPage
= _
"07/07/2007"
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default RunTime Error 1004? _Default Property?

I can't say if this will solve your problem or not, but
I have found it best to loop through the pivotitems in the page field and
find the pivotitem that contains the value you want to use, then set the
currentpage to the value of the pivotitem. This eliminates the chance of
screwing up your pivot table by assigning a non-existent item.

--
Regards,
Tom Ogilvy




"DarrenS" wrote:

Hi All,

I'm writing some code that automatically changes PageField Values in a
PivotTable. On one of them, I get a Run Time Error 1004 "Unable to set the
_Default property of the PivotItem Class".

Does anyone know what this means in this context? Below is a section of code
that I'm using, and it works ok on another field that I am doing it on...

ActiveSheet.PivotTables("PivotTable1").PivotFields ("Wk_Ending").CurrentPage
= _
"07/07/2007"

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default RunTime Error 1004? _Default Property?


Cheers Tom,

I know that the item is definitely there, because I also tried recording the
macro to make sure that the code, field names and values are exactly correct.
Playing back the recording still gives the same error...?


"Tom Ogilvy" wrote:

I can't say if this will solve your problem or not, but
I have found it best to loop through the pivotitems in the page field and
find the pivotitem that contains the value you want to use, then set the
currentpage to the value of the pivotitem. This eliminates the chance of
screwing up your pivot table by assigning a non-existent item.

--
Regards,
Tom Ogilvy




"DarrenS" wrote:

Hi All,

I'm writing some code that automatically changes PageField Values in a
PivotTable. On one of them, I get a Run Time Error 1004 "Unable to set the
_Default property of the PivotItem Class".

Does anyone know what this means in this context? Below is a section of code
that I'm using, and it works ok on another field that I am doing it on...

ActiveSheet.PivotTables("PivotTable1").PivotFields ("Wk_Ending").CurrentPage
= _
"07/07/2007"

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default RunTime Error 1004? _Default Property?

That's cool Darren. I set up a pivot table and recorded the code and got this:

Sub ABC()
'
' Macro3 Macro
' Macro recorded 07/09/2007 by OGILVTW
'

'
ActiveSheet.PivotTables("PivotTable1") _
.PivotFields("Date").CurrentPage = _
"07/07/2007"
End Sub

and it gave me an error as well (same as you).

I tried my advice:

Sub eFG()
Dim pi As PivotItem
With ActiveSheet.PivotTables("PivotTable1") _
.PivotFields("Date")
For Each pi In .PivotItems
If CDate(pi.Value) = CDate("07/07/2007") Then
.CurrentPage = pi.Value
End If
Next
End With
End Sub

And its working like a champ. I am changing dates in the code and it works
great. The only sad part is thinking about you sitting around with your
recorded code getting errors.

What actually does work (besides my way) going back to your old recorded
code way (at least for me) is to do

Sub ABC()
'
' Macro3 Macro
' Macro recorded 07/09/2007 by OGILVTW
' Modified by OGILVYTW after examining what the
' value of the pivot item actually is.

'
ActiveSheet.PivotTables("PivotTable1") _
.PivotFields("Date").CurrentPage = _
"7/7/2007"
End Sub

that worked, but the suggestion I made previously works without finding out
what it is actually looking for.

--
Regards,
Tom Ogilvy


"DarrenS" wrote:


Cheers Tom,

I know that the item is definitely there, because I also tried recording the
macro to make sure that the code, field names and values are exactly correct.
Playing back the recording still gives the same error...?


"Tom Ogilvy" wrote:

I can't say if this will solve your problem or not, but
I have found it best to loop through the pivotitems in the page field and
find the pivotitem that contains the value you want to use, then set the
currentpage to the value of the pivotitem. This eliminates the chance of
screwing up your pivot table by assigning a non-existent item.

--
Regards,
Tom Ogilvy




"DarrenS" wrote:

Hi All,

I'm writing some code that automatically changes PageField Values in a
PivotTable. On one of them, I get a Run Time Error 1004 "Unable to set the
_Default property of the PivotItem Class".

Does anyone know what this means in this context? Below is a section of code
that I'm using, and it works ok on another field that I am doing it on...

ActiveSheet.PivotTables("PivotTable1").PivotFields ("Wk_Ending").CurrentPage
= _
"07/07/2007"

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default RunTime Error 1004? _Default Property?

Wow, still no joy...

You know, I have a funny feeling there may be a problem with my PivotTables.
You see, I reaise now that it worked when I first did it, but when I ran one
of my Macros it started giving errors. I believe it could be something to do
with data types. The date in my source data isn't picked up by excel as a
date, so I convert the column to dates using the 'text to columns' function.
Does that sound like a culprit to you?

I'm gonna re-build my PivotTables and see how it goes and let you know.

Cheers
Darren

"Tom Ogilvy" wrote:

That's cool Darren. I set up a pivot table and recorded the code and got this:

Sub ABC()
'
' Macro3 Macro
' Macro recorded 07/09/2007 by OGILVTW
'

'
ActiveSheet.PivotTables("PivotTable1") _
.PivotFields("Date").CurrentPage = _
"07/07/2007"
End Sub

and it gave me an error as well (same as you).

I tried my advice:

Sub eFG()
Dim pi As PivotItem
With ActiveSheet.PivotTables("PivotTable1") _
.PivotFields("Date")
For Each pi In .PivotItems
If CDate(pi.Value) = CDate("07/07/2007") Then
.CurrentPage = pi.Value
End If
Next
End With
End Sub

And its working like a champ. I am changing dates in the code and it works
great. The only sad part is thinking about you sitting around with your
recorded code getting errors.

What actually does work (besides my way) going back to your old recorded
code way (at least for me) is to do

Sub ABC()
'
' Macro3 Macro
' Macro recorded 07/09/2007 by OGILVTW
' Modified by OGILVYTW after examining what the
' value of the pivot item actually is.

'
ActiveSheet.PivotTables("PivotTable1") _
.PivotFields("Date").CurrentPage = _
"7/7/2007"
End Sub

that worked, but the suggestion I made previously works without finding out
what it is actually looking for.

--
Regards,
Tom Ogilvy


"DarrenS" wrote:


Cheers Tom,

I know that the item is definitely there, because I also tried recording the
macro to make sure that the code, field names and values are exactly correct.
Playing back the recording still gives the same error...?


"Tom Ogilvy" wrote:

I can't say if this will solve your problem or not, but
I have found it best to loop through the pivotitems in the page field and
find the pivotitem that contains the value you want to use, then set the
currentpage to the value of the pivotitem. This eliminates the chance of
screwing up your pivot table by assigning a non-existent item.

--
Regards,
Tom Ogilvy




"DarrenS" wrote:

Hi All,

I'm writing some code that automatically changes PageField Values in a
PivotTable. On one of them, I get a Run Time Error 1004 "Unable to set the
_Default property of the PivotItem Class".

Does anyone know what this means in this context? Below is a section of code
that I'm using, and it works ok on another field that I am doing it on...

ActiveSheet.PivotTables("PivotTable1").PivotFields ("Wk_Ending").CurrentPage
= _
"07/07/2007"

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
Runtime Error 1004 Unable to set the top property of the picture c JB Bates[_2_] Excel Discussion (Misc queries) 1 March 3rd 10 08:04 PM
Hiding Rows Error - "Runtime Error 1004 - Unable to set the hidden property of the range class" Punsterr Excel Programming 2 April 9th 07 05:32 PM
Runtime Error 1004 Unable to set the XValues property of series cl Rachel Excel Programming 2 April 26th 06 02:41 PM
Runtime error 1004 - unable to set Visible property of Worksheet c SueJB Excel Programming 2 October 4th 05 02:27 PM
Runtime 1004 unable to get find property of range class Eric Excel Programming 2 January 30th 04 01:06 PM


All times are GMT +1. The time now is 12:40 PM.

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

About Us

"It's about Microsoft Excel"