PivotTables with Multiple Fields

Posted: 11-15-2006, 10:16 PM
Hey gang, I got a fun one.

I have a PivotTable with two page fields.

***The data that I'm describing is dummied up, but is illustrative of
the principle.***

In the data sheet that underlies the PivotTable, I have "City" in
column A, and "State" in Column B. I have a lookup table on another
sheet, so that to find the state associated with the city, it'd be:
=VLOOKUP(A2,stateName,2,false). So if "Sacramento" was in A2, then
"California" would be in B2. And so forth. I have "Date" in Column C,
and "Dollar Amount" in Column D.

My PivotTable has Date for the row field (grouped by month), Dollar
Amount in the data field, and then two page fields: first, the State,
then the City.

You can guess where this is going.

I want to get to the point where when the state page field changes, the
City page field shows only the cities associated with that state.

I modified some code from PivotTable legend Debra Dalgleish; it's kinda
working, but I wanted to get some help on maybe improving it. In
essence, I created a named range for each state. In B2, I created a
drop-down validation, using the named range "allStates" as the initial
source, and I put the Worksheet_Calculate code in the sheet containing
the PivotTable:

Private Sub Worksheet_Calculate()
'B2 is where the
Range("B2").Select
Select Case ActiveCell.Offset(-1, 0).Value
Case "California"
With Selection.Validation
.Delete
.Add Type:=xlValidateList,
AlertStyle:=xlValidAlertStop, Operator:=xlBetween,
Formula1:="=californiaCities"
.InCellDropdown = True
End With
Case "Nevada"
With Selection.Validation
.Delete
.Add Type:=xlValidateList,
AlertStyle:=xlValidAlertStop, Operator:=xlBetween,
Formula1:="=nevadaCities"
.InCellDropdown = True
End With
Case Else
With Selection.Validation
.Delete
.Add Type:=xlValidateList,
AlertStyle:=xlValidAlertStop, Operator:=xlBetween,
Formula1:="=allStates"
.InCellDropdown = True
End With
End Select
End Sub

What I'm really trying to avoid is having to have 50 named ranges, one
for each state. I'll do it if I have to, but I'm really trying to
avoid that; seems like it should be easier than that.

Any suggestions would be greatly appreciated.

Thanks!

Cheers
Geoff

Reply With Quote

Responses to "PivotTables with Multiple Fields"

 
LinkBack Thread Tools Display Modes
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[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
Mac pivottables don't refresh on a PC. mrl Mac Office Excel 0 06-02-2005 04:30 PM
Row limit and PivotTables Patrick Mac Office Excel 1 02-16-2005 08:50 PM
forms and fields maps@tomottoe.com Mac Office 2 12-07-2004 09:11 PM
Some fields are yellow! Brian-N Windows XP Help & Support 1 11-06-2003 06:16 PM
Photo fields Jose Windows XP Photos 1 08-08-2003 02:15 PM


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90