Autofilter a range based on column values

saffeeq

New Member
Joined
Sep 16, 2018
Messages
2
Hello
I am new to excel vba. I want to hide all the rows in the range (B9:Q1574) using excel vba code based on values in column Q.
I placed a button on sheet1(Home) to filter Data range in Sheet2(CB). I wrote the below code in click event of the Button.
Sheets("CB").Select
Worksheets("CB").Range("B9:Q1574").AutoFilter Field:=16, Criteria1:=">100"

But it doesn't work.
Can anyone help?
 

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 this:
Code:
Sub Filter_Me_Please()
'Modified  9/17/2018  1:07:30 AM  EDT
Application.ScreenUpdating = False
Sheets("CB").Select
    With Worksheets("CB").Range("B9:Q18")
        .AutoFilter Field:=16, Criteria1:=">100"
        counter = .Columns(16).SpecialCells(xlCellTypeVisible).Count
        If counter > 1 Then
            .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Hidden = True
        Else
            MsgBox "No values found"
        End If
    End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks for the reply.
Tried with the code.
It Works, but all rows gets hidden. I need to hide rows in which the value of column Q is less than 100.
 
Upvote 0
During testing I change this:
B9:Q18

Modify to your needs.

And if you still have problems.
Someone else here at Mr. Excel will have to help you. It's time for me to go to bed.
<strike>
</strike>
 
Upvote 0

Forum statistics

Threads
1,215,467
Messages
6,124,984
Members
449,201
Latest member
Lunzwe73

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