If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Need help updating Pivot table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-09-08, 09:06
Brent Blevins Brent Blevins is offline
Registered User
 
Join Date: Jun 2007
Posts: 65
Need help updating Pivot table

I am trying to automate updates to a pivot table. I used the macro recorder to get the syntax below:

Code:
ActiveSheet.PivotTables("InboundCalls").PivotFields ("[CallDates]").AddPageItem _
        "[CallDates].[All CallDates].[2008].[December].[5]", True
I then updated the code to include my date variables so that the report will always be updates with the current date:

Code:
 
'Get information about today's date
    strDate = Date
    strMonth = Format(strDate, "m")
    strMonthName = MonthName(strMonth)
    strDay = Format(strDate, "d")
    strYear = Format(strDate, "yyyy")
    strReportDate = strYear & strMonth & strDay
    
'Change the date on the first page
    Sheets("Summary").Select
    Cells(2, 1) = strDate
'Update the first 4 tabs (Set the Year Month and Day)
    Sheets("LecDaily").Select
    ActiveSheet.PivotTables("InboundCalls").PivotFields("[CallDates]").AddPageItem _
    "[CallDates].[All CallDates]." & [strYear] & "." & [strMonthName] & "." & [strDay] & ", True"
When the code executes I get an error that says:
Runtime error 1004
The item could not be found in the OLAP cube.

Any ideas on what might be causing this?
Reply With Quote
  #2 (permalink)  
Old 12-09-08, 10:10
Brent Blevins Brent Blevins is offline
Registered User
 
Join Date: Jun 2007
Posts: 65
I know it has to be something with the way I am using the variables because it works without the variables.

Any Ideas?

I also tried this:

Code:
 
Sheets("LecDaily").Select
ActiveSheet.PivotTables("InboundCalls").PivotFields("[CallDates]").AddPageItem _
"[CallDates].[All CallDates].[" & strYear & "].[" & strMonthName & "].[" & strDay & "], True"

Last edited by Brent Blevins; 12-09-08 at 14:56.
Reply With Quote
  #3 (permalink)  
Old 12-10-08, 09:38
shades shades is offline
Registered User
 
Join Date: Oct 2003
Posts: 1,091
Howdy. It might be easier to rebuild the entire Pivot Table with each update. If you look at Chapter 12 of VBA and Macros for MS Excel, by Bill Jelen, et al you will find all that you need. It not only explains the updating process, but provides several working examples. It actually is as fast as trying to update one item, and it cleans out all the other stuff that accumulates when trying to update. Once I began using that approach, it solved several other problems as well, such as getting around the limitations of the Pivot Tables.

For me, it was worth buying the book for that chapter alone.
__________________
old, slow, and confused
but at least I'm inconsistent!

Rich
(retired Excel 2003 user, 3/28/2008)

How to ask a question on forums
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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