Subscript out of range error?

olimits7

Board Regular
Joined
Oct 29, 2004
Messages
229
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm getting the "subscript out of range" error and I'm not sure what's causing it.

When I debug it, it stops at the following point:

Code:
 ActiveSheet.ListObjects("Table__2020_RevTM.accdb").Range.AutoFilter Field:=1

This is the whole function, it basically gives me this error when I save the new exported document to my desktop. When I look at the "Table__2020_RevTM.accdb" qryRev table in Access it seems to show up fine and the data also shows up fine in the file that I'm running this macro from.

Code:
Sub Export_Rep()
    Application.ScreenUpdating = False
    
    selRep = Range("selRep")  ' set var of rep name
    Qtr = Range("Qtr")        ' set qtr
    ConsQtr = Qtr & " Summary"   ' set var of consolidated quarter
    
    Call nwWorkbook(selRep, Qtr, ConsQtr)
    Call Comm_Export(selRep, Qtr, ConsQtr)
    Call Rev_Export(selRep, Qtr, ConsQtr)
    Call TM_Export(selRep, Qtr, ConsQtr)
    Call Export_SaveAs(selRep, Qtr, ConsQtr)
    
    Sheets("Reps REV").Select
    ActiveSheet.ListObjects("Table__2020_RevTM.accdb").Range.AutoFilter Field:=1
    
    Sheets("Reps T&M").Select
    ActiveSheet.ListObjects("Table__2020_RevTM.accdb28").Range.AutoFilter Field:=1
    
    Sheets(1).Select

End Sub

Does anyone have an idea of what could be causing this issue?

Thank you!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Does anyone have an idea or can help point me in the right direction to see what is causing this?

Thank you!
 
Upvote 0
Enter ...

Code:
? Activesheet.ListObjects(1).Name

... in the Immediate window. What's it return?
 
Upvote 0
Hi @MrExcel MVP

You mean add the following to my code and then try running this again?

Code:
Sheets("Reps REV").Select
    ActiveSheet.ListObjects("Table__2020_RevTM.accdb").Range.AutoFilter Field:=1
    Print ActiveSheet.ListObjects(1).Name
    
    Sheets("Reps T&M").Select
    ActiveSheet.ListObjects("Table__2020_RevTM.accdb28").Range.AutoFilter Field:=1

When I do this I get a compile error: method not suitable without proper object

Thank you!
 
Upvote 0
No, that's not what I mean.

If you enter what I posted in the Immediate window, it will return the name of the table. What you have is incorrect; that's why you're getting the subscript error.
 
Upvote 0
Oh ok, I see what you mean; when I did that I see it shows "Table__2019_RevTM.accdb" but I'm not sure why it's still pointing to that table when I changed the code to show "Table__2020_RevTM.accdb".

In the Queries & Connections window for this connection I see under the "Used In" tab it's showing "Table__2019_RevTM.accdb" but not sure where it's pulling this name from.

Thank you, again!
 
Upvote 0
Oh ok, I was able to see under the "Name Manager" window the name was still showing 2019 instead of 2020; when I made this change it works properly now.

Thank you for pointing me in the right direction!
 
Upvote 0
Glad you got it sorted, you're welcome.
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,044
Members
449,063
Latest member
ak94

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