Define existing pivotTable as object in VBA

thomas819

New Member
Joined
Nov 23, 2020
Messages
36
Office Version
  1. 2019
Platform
  1. Windows
Hello all,
can somebody explain to me how is posibble following situation:

VBA Code:
Sub Top10filter()

    Dim pt As PivotTable
    Dim Field As PivotField
    
    Set pt = Worksheets("Kalkulácie").PivotTables("TOP")
    Set Field = pt.PivotFields("[sumarizácia].[Celé meno].[Celé meno]")
    Set Sh = Sheets("Kalkulácie")
    
       Field.ClearAllFilters
       Field.PivotFilters.Add2 Type:=xlTopCount, _
            DataField:=Sh.PivotTables("TOP").CubeFields( _
            "[Measures].[Súčet Prac. dni mimo práce]"), Value1:=Sh.Range("C1").Value
    
End Sub

When I use this VBA on my private computer is working as charm :)
but when I used this exactly same VBA in Sharepoint folder, suddenly it is not working at all.
I got this error:
Run-time error '9':
Subscrpit out of range

Only reason what I can think of... I need somehow define to variable for CubeFields. Am I right? Or is there something more to this issue?

I will be gratefull for your help :)
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,213,497
Messages
6,113,999
Members
448,543
Latest member
MartinLarkin

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