Consulting

Results 1 to 5 of 5

Thread: Solved: Refresh my pivot table

  1. #1

    Solved: Refresh my pivot table

    Hi all,

    I want to refresh my pivot table (sheet1) by referring the data of sheet2 by simply writing the VBA code.

    Data of sheet2 are frequently changing. The recorded macro is below.

    [VBA]sub macro()
    Sheets("Overview").Select
    ActiveSheet.PivotTables("PivotTable4").ChangePivotCache ActiveWorkbook. _
    PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "C:\Desktop\[asd.xlsm]RAW DATA!R1C1:R30C6", Version:= _
    xlPivotTableVersion14)
    Range("C20").Select
    ActiveSheet.PivotTables("PivotTable4").PivotCache.Refresh
    End Sub
    [/VBA]
    Advance thanks
    Attached Files Attached Files
    Last edited by Aussiebear; 03-05-2013 at 07:34 PM. Reason: Added the correct tags to the supplied code

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [VBA]Sub macro()

    With Sheets("Sheet1")

    .PivotTables("PivotTable4").ChangePivotCache _
    ActiveWorkbook.PivotCaches.Create( _
    SourceType:=xlDatabase, _
    SourceData:=Worksheets("Sheet2").UsedRange, _
    Version:=xlPivotTableVersion14)
    End With

    ActiveSheet.PivotTables("PivotTable4").PivotCache.Refresh
    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

  3. #3
    Hello Xld,
    Its working perfectly. One simple query.

    Suppose I run the macro in active sheet "sheet2". It refreshes the pivot but I am getting error like

    Run-time error '1004'
    Unable to get the PivotTables property of the worksheet class


    Advance thanks

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this modification

    [VBA]Sub macro()

    With Sheets("Sheet1")

    .PivotTables("PivotTable4").ChangePivotCache _
    ActiveWorkbook.PivotCaches.Create( _
    SourceType:=xlDatabase, _
    SourceData:=Worksheets("Sheet2").UsedRange, _
    Version:=xlPivotTableVersion14)

    .PivotTables("PivotTable4").PivotCache.Refresh
    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

  5. #5
    Thanks Xld for ur kind help

Posting Permissions

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