Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Refreshed Pivot Table still have old items


I have a worksheet named range that changes. On another worksheet (i
the same workbook) I have a Pivot Table that uses the named range a
the data source. And as we all know, Pivot tables don't refres
themselves, I have a macro that does just that - refresh the pivo
table whenever the named range changes. Anyway, I also want to writ
the data from the pivot table onto a another worksheet for whisch
have subroutine (see code below). Unfortunately, when the pivot tabl
refreshes, the combo box for the Row data item retains the old items
Ofcourse these items have no corresponding column data value. So th
problem at hand, is that when I scroll through the code to write th
data from the Pivot Table to the other worksheet, it writes th
invisible data row items - which of course I don't want. I just wan
the current visible items.


Code
-------------------

Public Sub Write_PivotData2()

Dim pvtTable As PivotTable
Dim pvtItem As PivotItem

Set nwSheet = Worksheets("MDTRPT")
Set pvtTable = Worksheets("PIR-DT DESC").PivotTables("PIR1DTDESC")

rw = 12
For Each pvtItem In pvtTable.PivotFields("DTDESC").PivotItems
rw = rw + 1
nwSheet.Cells(rw, 2).Value = pvtItem.Name
Next pvtItem

End Sub


-------------------


I even tried using VisibleItems instead of PivotItems and that didn'
work either
I even tried to circumvent writing the "invalid" data row items b
using "On Error Resume Next", but this wouldn't work because I stil
can't tell the difference what are the current visible data row item
and what are the old one. Because the column data value does no
exist, I get an error trying to determine if it is NULL (see cod
below) - "The formula is not complete. Make sure an ending squar
bracket ] is not missing"



Code
-------------------

Public Sub Write_PivotData()

Dim pvtTable As PivotTable
Dim pvtItem As PivotItem
Dim pvtSumValue As Double
Dim pvtItemValue As String

Set nwSheet = Worksheets("MDTRPT")
Set pvtTable = Worksheets("PIR-DT DESC").PivotTables("PIR1DTDESC")

rw = 12

For Each pvtItem In pvtTable.PivotFields("DTDESC").VisibleItems
pvtItemValue = pvtItem.Name
pvtSumValue = pvtTable.GetData(pvtItemValue) 'Error occurs on this line
If IsNull(pvtSumValue) Then
'It is a Pivot field from before
Else
rw = rw + 1
nwSheet.Cells(rw, 2).Value = pvtItem.Name
End If
Next pvtItem

End Sub

-------------------

--
suzette
-----------------------------------------------------------------------
suzetter's Profile: http://www.excelforum.com/member.php...nfo&userid=707
View this thread: http://www.excelforum.com/showthread.php?threadid=39022

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Refreshed Pivot Table still have old items

There's information here on clearing old items in a pivot table:


http://www.contextures.com/xlPivot04.html


suzetter wrote:
I have a worksheet named range that changes. On another worksheet (in
the same workbook) I have a Pivot Table that uses the named range as
the data source. And as we all know, Pivot tables don't refresh
themselves, I have a macro that does just that - refresh the pivot
table whenever the named range changes. Anyway, I also want to write
the data from the pivot table onto a another worksheet for whisch I
have subroutine (see code below). Unfortunately, when the pivot table
refreshes, the combo box for the Row data item retains the old items.
Ofcourse these items have no corresponding column data value. So the
problem at hand, is that when I scroll through the code to write the
data from the Pivot Table to the other worksheet, it writes the
invisible data row items - which of course I don't want. I just want
the current visible items.


Code:
--------------------

Public Sub Write_PivotData2()

Dim pvtTable As PivotTable
Dim pvtItem As PivotItem

Set nwSheet = Worksheets("MDTRPT")
Set pvtTable = Worksheets("PIR-DT DESC").PivotTables("PIR1DTDESC")

rw = 12
For Each pvtItem In pvtTable.PivotFields("DTDESC").PivotItems
rw = rw + 1
nwSheet.Cells(rw, 2).Value = pvtItem.Name
Next pvtItem

End Sub


--------------------


I even tried using VisibleItems instead of PivotItems and that didn't
work either
I even tried to circumvent writing the "invalid" data row items by
using "On Error Resume Next", but this wouldn't work because I still
can't tell the difference what are the current visible data row items
and what are the old one. Because the column data value does not
exist, I get an error trying to determine if it is NULL (see code
below) - "The formula is not complete. Make sure an ending square
bracket ] is not missing"



Code:
--------------------

Public Sub Write_PivotData()

Dim pvtTable As PivotTable
Dim pvtItem As PivotItem
Dim pvtSumValue As Double
Dim pvtItemValue As String

Set nwSheet = Worksheets("MDTRPT")
Set pvtTable = Worksheets("PIR-DT DESC").PivotTables("PIR1DTDESC")

rw = 12

For Each pvtItem In pvtTable.PivotFields("DTDESC").VisibleItems
pvtItemValue = pvtItem.Name
pvtSumValue = pvtTable.GetData(pvtItemValue) 'Error occurs on this line
If IsNull(pvtSumValue) Then
'It is a Pivot field from before
Else
rw = rw + 1
nwSheet.Cells(rw, 2).Value = pvtItem.Name
End If
Next pvtItem

End Sub

--------------------




--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

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
Timestamp for when Pivot table was last refreshed Abi Excel Discussion (Misc queries) 1 September 8th 08 04:36 PM
Pivot Table vanishes when refreshed Mike W Excel Worksheet Functions 1 February 1st 08 07:06 AM
Pivot Table format changes when data is refreshed Bendinblues Excel Discussion (Misc queries) 8 October 22nd 07 02:45 PM
Pivot Table to be refreshed whenever the web query is being refres Vicky Excel Discussion (Misc queries) 0 July 16th 06 10:28 AM
Is there a way to compare a pivot table refreshed data to old one Wes Excel Discussion (Misc queries) 1 July 6th 05 05:34 PM


All times are GMT +1. The time now is 07:47 PM.

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

About Us

"It's about Microsoft Excel"