Excel VBA Macro: Changing and filtering pivot works for me, not for my colleagues

hoksie

New Member
Joined
Dec 28, 2015
Messages
1
Hi all,

Thanks in advance for your help. I found a lot of nice tips and tricks on this forum!

Situation:
I have created a dashboard based on a pivot table. I use different macros to filter data and change the dashboard. I have made different rectangles where I assign macros to. I have two types of macros. First kind of macro uses the autofilter, the other kind of macro changes the pivot table. I change the pivot table by filtering the data and the a macro takes away column headers and place new column headers instead. I recorded this macro.

My problem:
It works fine for me, but not for my two colleagues. They get the following message (translated out of Dutch): ‘Error 1004 during execution by application or object-defined error’. They opened it out of the mail and on a shared file station. It makes no difference. The strange thing: the macros using autofilter are working, the macros using pivot (either filtering or changing) doesn’t work. We use all Excel 2010 and work for the same company. Changing macro security doesn’t make a difference.

At the bottom of this forum message is one of my macros which isn’t working. Sorry for the Dutch language in the macro (‘draaitabel’ is the dutch word for pivot).

Explanation of the macro:
I have different hierarchy levels which I want to change in my pivot table. In this example I want to take away all levels (i.e. ‘C COUNTRY H’, ‘L LOCATION H’ etc.) and put in the team level (‘T TEAM H’). After that I change the color of the button, so I can see which button is selected. In my dashboard level ‘F FLOOR H’ is now selected. When I run the query I get an error message at: ‘ActiveSheet.PivotTables("Draaitabel1").CubeFields( _
"[Organisatie].[F FLOOR H]").Orientation = xlHidden’

Hopefully somebody can help me!

Macro:
Sub Niveau_Team()
ActiveSheet.PivotTables("Draaitabel1").CubeFields( _
"[Organisatie].[C COUNTRY H]").Orientation = xlHidden
ActiveSheet.PivotTables("Draaitabel1").CubeFields( _
"[Organisatie].[L LOCATION H]").Orientation = xlHidden
ActiveSheet.PivotTables("Draaitabel1").CubeFields( _
"[Organisatie].[F FLOOR H]").Orientation = xlHidden
ActiveSheet.PivotTables("Draaitabel1").CubeFields( _
"[Organisatie].[T TEAM H]").Orientation = xlHidden
ActiveSheet.PivotTables("Draaitabel1").CubeFields( _
"[Organisatie].[E NAME]").Orientation = xlHidden
With ActiveSheet.PivotTables("Draaitabel1").CubeFields( _
"[Organisatie].[T TEAM H]")
.Orientation = xlColumnField
.Position = 1
End With
‘Here starts the macro changing the button colors, depending on the button choice.
ActiveSheet.Shapes.Range(Array("Rectangle 1")).Select
With Selection.ShapeRange.ThreeD
.SetPresetCamera (msoCameraOrthographicFront)
.RotationX = 0
.RotationY = 0
.RotationZ = 0
.FieldOfView = 0
.LightAngle = 308
.PresetLighting = msoLightRigChilly
.PresetMaterial = msoMaterialClear
.Depth = 0
.ContourWidth = 0
.BevelTopType = msoBevelCircle
.BevelTopInset = 6
.BevelTopDepth = 5
.BevelBottomType = msoBevelNone
End With
Selection.ShapeRange.Shadow.Visible = msoFalse
Selection.ShapeRange.Line.Visible = msoFalse
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.5
.Transparency = 0
.Solid
End With
ActiveSheet.Shapes.Range(Array("Rectangle 3")).Select
With Selection.ShapeRange.ThreeD
.SetPresetCamera (msoCameraOrthographicFront)
.RotationX = 0
.RotationY = 0
.RotationZ = 0
.FieldOfView = 0
.LightAngle = 308
.PresetLighting = msoLightRigChilly
.PresetMaterial = msoMaterialClear
.Depth = 0
.ContourWidth = 0
.BevelTopType = msoBevelCircle
.BevelTopInset = 6
.BevelTopDepth = 5
.BevelBottomType = msoBevelNone
End With
Selection.ShapeRange.Shadow.Visible = msoFalse
Selection.ShapeRange.Line.Visible = msoFalse
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = -0.5
.Transparency = 0
.Solid
End With
ActiveSheet.Shapes.Range(Array("Rectangle 2")).Select
Selection.ShapeRange.ShapeStyle = msoShapeStylePreset39
ActiveSheet.Shapes.Range(Array("Rectangle 2")).Select
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
.Solid
End With

End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,214,911
Messages
6,122,196
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top