Error "Subscript out of range"

Biel

New Member
Joined
Mar 25, 2020
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hello Evrybody,

I'm making a little test to filter from a cell value another workbook with all lot of pivot table.
I make a little test and create the vba but it's keep giving to me the same error but the references to pivottable and sheet is ok.
1585125562968.png

I hope you can help

Stay safe!!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
You use the wrong "doublequote" for the sheet and pivottable name
Also, since the code in in Sheet2 code module, you can use "Me".
VBA Code:
Set pt = Me.PivotTables("PivotTable1")
Bye
 
Upvote 0
Don't worry, you will certainly have more complicated problems in the future ;)
 
Upvote 0
Hello,

Sorry, but when I tried to the original file with all the pivot table it's not working.
I have another problem "Run Time Error 1004 'Unable to get the PivotFields property of the PivotTable class"

1585155642367.png

What I want to do is filter 2 fields from value coming from a cell of the different Pivot table in the sheet. (All pivot table has the same fields)

Thanks so much for you help, I'm new with that and I'm learning.

I appreciate a lot.


Biel Bulbena
 
Upvote 0
It looks like you're missing an 's' in PivotFields...

VBA Code:
Set Field = pt.PivotFields("Turno")

Hope this helps!
 
Upvote 0
Yes I seen it afterwards but I have the same problem
 
Upvote 0
Are you sure that the table you are pointing to is named PivotTable4?
Try using
Code:
Set pt = Me.Range("AM1").PivotTable
Debug.Print pt.Name
See Fields =pt.PivotFields("Turno")

If it does work, then open the vba "Immediate window" and you will see the actual name of that pivot; to open the Immadiate window, from vba press Contr-g, or use Menu /View /Immediate window.
And, going further in your code, be aware that your With pt /End With structure is useless, as you never refer (in the 3 instructions within the structure) the object set by the With statement; it is not harmful, its useless and you may remove the two lines /( With pt and End With)

Bye
 
Upvote 0
Hello,

Yes as you can see in the imatge in the second post, the pivot table name is correct.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Intersect(Target, Range("AG3:AG4")) Is Nothing Then Exit Sub

Dim pt As PivotTable
Dim Field As PivotField
Dim Cat As String

Set pt = Me.Range("AM1").PivotTable
Debug.Print pt.Name
See Fields = pt.PivotFields("Turno")

Field.ClearAllFilters
Field.CurrentPage = Cat
pt.RefreshTable

End Sub


This its not working :)

Thanks a lot for the help
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,507
Members
452,917
Latest member
MrsMSalt

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