Subscript Out of Range Error in VBA

yatri82

New Member
Joined
Jul 11, 2017
Messages
1
Hey All,

I have the following code in one of my Excel files. Using it to automatically filter team based on what is selected on the home screen.
There are various charts which are then processed based on the filter selection.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

ActiveSheet.AutoFilterMode = False
Worksheets("Admin").Range("B166:V166").AutoFilter
Worksheets("Admin").Range("B166:V166").AutoFilter Field:=3, Criteria1:=Worksheets("Admin").Range("C8").Text


End Sub

All was fine until yesterday, I haven't made any major change or renamed anything in the file. Getting all sorts of errors today. Apparently, it works fine when I just select 'continue'.

Two errors I have received today.

1.) Code execution interrupted - Searched and found that this can be resolved just my hitting Cntrl+Break and/or restarting the system. Didn't happen again.

2.) Subscript out of range (Error 9)
Disappeared when I selected continue, closed and reopened the file.

I am fine if this is one-off but if these errors come, they affect user confidence in the authenticity of the reports. Scares them away, if you guys know what I mean.

Cheers! :)
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,214,622
Messages
6,120,576
Members
448,972
Latest member
Shantanu2024

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