Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default CalculatedFields.add function not working when refreshed...

I am updating a pivot table based on the users input from a drop down box.

The rows will become one of four different options based on that input, but
I'd also like to add a RANK to their return - which is a running total
calculated field.

When I run the calculated field the first time it works fine, however, when
I refresh, it seems to want to add it again and it gives me an error. It
won't let me reference the calculated field like it does the real fields
either.

I'm stuck, can ya' help?

J

Public Sub changepivot()

Dim P As PivotTable
Set P = Worksheets("Capital").PivotTables("FakePivot")
Set PRegion = P.PivotFields("Region")
Set PState = P.PivotFields("State")
Set PTotal1 = P.PivotFields("Total1")
Set Prank = P.CalculatedFields("Rank")

If Range("Selected").Value = "All" Then
With P
PRegion.Orientation = xlHidden
PState.Orientation = xlHidden
End With
ElseIf Range("Selected").Value = "Gulf" Or Range("Selected").Value =
"Atlantic" Or Range("Selected").Value = "North" Or Range("Selected").Value =
"Florida" Then
With P
With PRegion
.Orientation = xlRowField
.AutoSort xlDescending, "Sum of Total1"
.Position = 1
End With
PState.Orientation = xlHidden
.CalculatedFields.Add "Rankb", "=1" 'THIS IS WHERE IT ERRORS
End With
Else
With P
With PState
.Orientation = xlRowField
.AutoSort xlDescending, "Sum of Total1"
.Position = 1
End With
PRegion.Orientation = xlHidden
End With
End If

End Sub

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
ISBLANK function not working when cell is blank dut to function re mcmilja Excel Discussion (Misc queries) 9 May 7th 23 03:43 AM
Newly created Get Function is not working when I copied the syntax from a working function CJ Excel Programming 1 January 16th 07 05:28 AM
calculatedfields Geoff Excel Programming 2 June 24th 05 04:36 PM
CalculatedFields in Pivots Geoff[_8_] Excel Programming 0 October 5th 03 11:03 AM
Date/Time data source refreshed function Grant[_4_] Excel Programming 1 July 22nd 03 11:52 PM


All times are GMT +1. The time now is 07:07 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"