Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default Set PivotField to predefined value with check

I suspect the problem is in your data. Could you have misspelled a field name
(trailing spaces, etc.) or mismatched a field with a pivot table?

I tested your code with a pivot table and it worked fine.

Regards,

Hutch

"s80NL" wrote:


Tom,

If made the following out of your suggestion:


Formula:
--------------------
Function CheckFld(WS As String, PT As String, PF As String, OptionX As String) As Boolean
Dim i As Long

Sheets(WS).Select
For i = 1 To ActiveSheet.PivotTables(PT).PivotFields(PF).PivotI tems.Count
If ActiveSheet.PivotTables(PT).PivotFields(PF).PivotI tems(i) = OptionX$ Then
CheckFld = True
Exit Function
End If
Next i
CheckFld = False
End Function
Sub RefreshSettings()
For i = 2 To 8
Dim WS As String, PT As String, PF As String, Option1 As String, Option2 As String, Option3 As String
WS = s0.Range("A" & i).Value
PT = s0.Range("B" & i).Value
PF = s0.Range("C" & i).Value
Option1 = s0.Range("D" & i).Value
Option2 = s0.Range("E" & i).Value
Option3 = s0.Range("F" & i).Value

Sheets(WS).Select
If CheckFld(WS, PT, PF, Option1) = True Then
ActiveSheet.PivotTables(PT).PivotFields(PF).Curren tPage = Option1
ElseIf CheckFld(WS, PT, PF, Option2) = True Then
ActiveSheet.PivotTables(PT).PivotFields(PF).Curren tPage = Option2
ElseIf CheckFld(WS, PT, PF, Option3) = True Then
ActiveSheet.PivotTables(PT).PivotFields(PF).Curren tPage = Option3
End If
Next i
End Sub
--------------------


As you can see I've put all information regarding WorkSheet names,
PivotTable names, PivotField names and 3 options in a sheet named s0.

But now I get an error for: -For i = 1 To
ActiveSheet.PivotTables(PT).PivotFields(PF).PivotI tems.Count-

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

Any idea what is going wrong and why? Thanks for your help!


--
s80NL


------------------------------------------------------------------------
s80NL's Profile: http://www.excelforum.com/member.php...o&userid=36374
View this thread: http://www.excelforum.com/showthread...hreadid=561596


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
PivotField refreshment witek Excel Programming 1 July 13th 06 05:58 PM
PivotField AfterUpdate event? Snowsride Excel Programming 0 January 11th 06 01:12 PM
PivotField select all CinqueTerra Excel Programming 3 December 11th 05 12:55 AM
How can I hide-Unhide pivotfield using VBA? MB Excel Programming 0 March 16th 05 09:57 PM
Hiding a pivotfield using code Todd Huttenstine Excel Programming 1 June 10th 04 05:01 PM


All times are GMT +1. The time now is 10:11 AM.

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

About Us

"It's about Microsoft Excel"