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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How prompt for date input in Pivot Table? 1

Status
Not open for further replies.

Jaffey

Technical User
Joined
Jul 18, 2006
Messages
72
Location
CA
I have a macro attached to a control button that changes the date on 50 different pivot tables similar to this:

Sheets("AMEX").Select
ActiveSheet.PivotTables("PivotTable55").PivotFields("Date").CurrentPage = _"Mon 11/27"
ActiveSheet.PivotTables("PivotTable38").PivotFields("Date").CurrentPage = _"Mon 11/27"

Currently I do a search & replace using VB editor to change the dates before pressing the button. I would like to prompt the user to input the date instead when the button is pressed. How can I add that? Many thanks.
 
Pls ignore this post - Skip replied to it with a solution in the Visual Basic(Microsoft): Version 5 & 6 forum.
 
I don't know much about pivot tables, but
is that the part you edit in VB editor?

Sheets("AMEX").Select
ActiveSheet.PivotTables("PivotTable55").PivotFields("Date").CurrentPage = "Mon 11/27"
ActiveSheet.PivotTables("PivotTable38").PivotFields("Date").CurrentPage = "Mon 11/27"

If so, Date is a reserved word and it gives you current date.

Try:
Code:
Sheets("AMEX").Select
ActiveSheet.PivotTables("PivotTable55").PivotFields("[b] & Date & [/b]").CurrentPage = _"Mon 11/27"
ActiveSheet.PivotTables("PivotTable38").PivotFields("[b] & Date & [/b]").CurrentPage = _"Mon 11/27"

But if you need to replace "Mon 11/27" try
Code:
MsgBox Format$(Weekday(Date, vbSunday), "ddd") & " " & Day(Date) & "/" & Month(Date)
It should give you Mon 11/12

HTH

---- Andy
 



Hi,
Code:
dim ws as worksheet, pvt as pivottable, dMyDate as Date
dMyDate = inputbox("enter date")
for each ws in worksheets
  for each pvt in ws.pivottables
    pvt.").PivotFields("Date").CurrentPage = Format(dMyDate, "ddd mm/dd")
  next
next


Skip,

[glasses] [red][/red]
[tongue]
 
Skip, your solution works fine on my machine but when the intended user tries it from hers she gets run time error: "Unable to set the Default Property of the PivotItem Class". I thought it might have something to do with her macro security settings but they are already set to low. Then I noticed she's only using MS Excel 2000.
 



On her machine, is the field named "Date" and is it the PAGE field?

Skip,

[glasses] [red][/red]
[tongue]
 
It's the exact same spreadsheet....we both access it from the same shared folder.
 


oops. I saw something I did not like...
Code:
dim ws as worksheet, pvt as pivottable, dMyDate as Date
dMyDate = inputbox("enter date")
for each ws in worksheets
  for each pvt in ws.pivottables
    pvt.PivotFields("Date").CurrentPage = Format(dMyDate, "ddd mm/dd")
  next
next
PLEASE replace your code.

Skip,

[glasses] [red][/red]
[tongue]
 
Skip, I had already removed the .") typo. After she got the error I opened it again on my machine and it still runs fine.
 


try this...
Code:
pvt.PivotFields("Date").CurrentPage[b].name[/b] = Format(dMyDate, "ddd mm/dd")


Skip,

[glasses] [red][/red]
[tongue]
 
your change works for me but now she's getting a name not defined error on her machine
 



Try Help/Detect & repair.

Short of that, reload Office

Skip,

[glasses] [red][/red]
[tongue]
 
The exact error is "Unable to set the Name Property of the PivotItem Class". Does that help?
 


Try Help/Detect & repair.

Short of that, reload Office

Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top