Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
ISBLANK function not working when cell is blank dut to function re | Excel Discussion (Misc queries) | |||
Newly created Get Function is not working when I copied the syntax from a working function | Excel Programming | |||
calculatedfields | Excel Programming | |||
CalculatedFields in Pivots | Excel Programming | |||
Date/Time data source refreshed function | Excel Programming |