Error on Autofilter

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,922
Office Version
  1. 365
Platform
  1. Windows
Hi,

On the following code, can someone explain why it's failing with error after the line in red is excuted with error message

"Run-time error '424' Object required"

Rich (BB code):
If ActiveSheet.AutoFilterMode Then .AutoFilter = False
    If SecurityLevel < 2 Then
        With Range(Range(ActiveCell.Offset(-1, 0), ActiveCell.End(xlToRight)), ActiveCell.End(xlDown))
            .AutoFilter = True
        End With
    End If

I think it's something to do with the range I'm trying to select and apply autofilter to but I'm not sure how to achieve what I want.

Thanks,
Jack
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try:-
Code:
If ActiveSheet.AutoFilterMode Then .AutoFilter = False
    If SecurityLevel < 2 Then
        With Range(ActiveCell.Offset(-1, 0), ActiveCell.End(xlToRight)
            .AutoFilter = True
        End With
    End If

I could be wrong but I think you only need to select the headers to set the autofilter.
 
Upvote 0
Thank you Andrew and Richard, am now using:
Code:
    If SecurityLevel < 2 Then
        If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
        ActiveCell.CurrentRegion.AutoFilter
    End If
Richard - have had problems before when only selecting the "header" row to filter for results, selecting the whole range I want filtered ensures it is that area only. I may be wrong about this, but it works so I'm happy!

Thanks again,
Jack
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,357
Members
452,907
Latest member
Roland Deschain

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