CubeFields

T

Tony

I am trying to make a PivotTable change the selected field using the code
below.

The part in PIVOTTABLE1 below works fine when I hard code the field names in
the code but will not work when I try to reference the field names.

When I run the PIVOTTABLE2 part of the code below I get a "Run-Time error
'9' Subscript out of range." error.

Does anyone know how to fix this so I can make the CubeFields reference a
range name rather than me hard coding it?

In the code below "curvar_h" and "selvar_h" are range names within my
spreadsheet.

_____________________________________________________________________
Private Sub ComboBox1_Change()

'Change PivotTable Variable - Detail Tables


Dim hidevar_h
Dim newvar_h
hidevar_h = Evaluate("curvar_h").Value
newvar_h = Evaluate("selvar_h").Value
ActiveSheet.PivotTables("PivotTable1").CubeFields("[homeowner]"). _
Orientation = xlHidden
With ActiveSheet.PivotTables("PivotTable1").CubeFields("[lapse]")
.Orientation = xlColumnField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable2").CubeFields(hidevar_h). _
Orientation = xlHidden
With ActiveSheet.PivotTables("PivotaTable2").CubeFields(newvar_h)
.Orientation = xlColumnField
.Position = 1
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top