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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
In addition, add these lines:
VBA Code:
Set pt = Sheets("PivotT").Range("B1").PivotTable
Debug.Print pt.Name
'ADD NEXT 3 LINES:
For I = 1 To pt.PivotFields.Count
    Debug.Print "*" & pt.PivotFields(I) & "*"
Next I

See Fields = pt.PivotFields("Turno")

FIEld.ClearAllFilters
FIEld.CurrentPage = Cat
pt.RefreshTable
Then try. When you get the error open the vba Immediate window and check wich is the name of the available fileds; they are listed this way: *FieldName* (the asterixs are for delimiting the FieldNames). Check that there is one *Turno*

Bye
 
Upvote 0
Hello,

This is the error
1585214018632.png

1585213974989.png

Actual VBA Code:
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
'ADD NEXT 3 LINES:
For i = 1 To pt.PivotFields.Count
    Debug.Print "*" & pt.PivotFields(i) & "*"
Next i

See Fields = pt.PivotFields("Turno")


Field.ClearAllFilters
Field.CurrentPage = Cat
pt.RefreshTable


End Sub


Nothing appearrs in immeditate window.
 
Upvote 0
Anthony said:
Don't worry, you will certainly have more complicated problems in the future ;)
I seem that the time has come…

So, it seems that now your Worksheet_SelectionChange is no longer accepted, wereas in post #6 the problem was with a failing instruction…
Immediate window is empty because the sub did not run.

Remove the complete Sub Worksheet_SelectionChange and reinsert the code you was using when you inserted post #6, and test from the beginning

If it fails as in post #6 then try adding the modifications for using Me.Range("AM1").PivotTable plus the For I = 1 To pt.PivotFields.Count /Next I cycle.
If it fails like in post#13 then you should try (1) restart your pc, and (2) the procedure for Office Repair

Bye
 
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,519
Members
452,921
Latest member
BBQKING

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