Consulting

Results 1 to 8 of 8

Thread: Getting the PivotTable Page data from another sheet

  1. #1
    VBAX Tutor lynnnow's Avatar
    Joined
    Jan 2005
    Location
    Mumbai, Maharashtra, India
    Posts
    299
    Location

    Getting the PivotTable Page data from another sheet

    Hi,

    I've set up a PivotTable and the pivot page data dropdown gets populated from the database. This date changes on a daily basis. Is there a way to automatically set this date to the current date? I tried putting a reference formula for example: In the pivot page field, I put ='Error Log'!A1. However, this kinda causes an overload on the system and the pivot doesn't work well, leading to the workbook crashing.

    Can this be done?

    Please see the attachment for an example.

    Lincoln

  2. #2
    VBAX Tutor lynnnow's Avatar
    Joined
    Jan 2005
    Location
    Mumbai, Maharashtra, India
    Posts
    299
    Location
    Bump...

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub Workbook_Open()
    On Error Resume Next
    With ThisWorkbook

    .Worksheets("Pivot").PivotTables("PivotTable1").PivotFields("Date").Current Page = Date
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Tutor lynnnow's Avatar
    Joined
    Jan 2005
    Location
    Mumbai, Maharashtra, India
    Posts
    299
    Location
    Thanks xld. I had used a modified version of this code like so:

    [VBA]ActiveSheet.PivotTables("PivotTable2").PivotFields("Date").CurrentPage = _
    Sheets("Error Log").Range("A1").Value[/VBA]

    I put it in the Worksheet_Activate event. However using the code you provided it doesn't work either.

    The "current date" in my post at #1 is a date on another sheet (Error Log) that is updated when I need it updated (which is in the date format).

    The pivot does not refresh even with the use of
    [VBA]ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh[/VBA]

    Am I doing something wrong? The pivotcache.refresh line I got from recording the macro. Does it need to be changed to a much swankier line(s) of code?

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    The pivot table in your workbook is called PivotTable1.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Tutor lynnnow's Avatar
    Joined
    Jan 2005
    Location
    Mumbai, Maharashtra, India
    Posts
    299
    Location
    Thanks for pointing that out, missed that. Works gr8.

    Thank you xld.

    However, please let me know why the code I did would not work. Aren't they the same thing?

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    They don't look remotely the same to me. You had a formula (to a non-existent sheet), I had workbook open event code.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Tutor lynnnow's Avatar
    Joined
    Jan 2005
    Location
    Mumbai, Maharashtra, India
    Posts
    299
    Location
    This is what I have used so far:

    [vba]Private Sub Worksheet_Activate()
    On Error Resume Next
    'ActiveSheet.PivotTables("PivotTable2").PivotFields("Date").CurrentPage = Sheets("Error Log").Range("A1").Value

    With ThisWorkbook
    .Worksheets("Monthly Locationwise").PivotTables("PivotTable2").PivotFields("Date").CurrentPage = _
    Sheets("Error Log").Range("A1").Value
    End With

    ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
    End Sub
    [/vba]
    The commented one is the one I had used which did not give me the desired result and the working one follows that. In essence I feel that they are the same. The example WB I had provided does not have the sheet names and pivot table as mentioned by the code you provided, but in effect have been changed to suit, yet the code you provided works and the one I tried failed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •