VBA Filter with Multiple Criteria

anwilson

New Member
Joined
Apr 17, 2019
Messages
13
Mornin Ya'll.

I've got a question on sheet 2 asking for a pressure, and a column on sheet 1 with multiple flange ratings. What I'd like the script to do is filter the flange ratings based on the pressure entered.

For example, if the user entered 350 psi it would filter out everything below 350 (100# and 300#) but show everything above 350 (600#, 900#, 1500#, and 2500#).

I was trying to use the AutoFilter function but can't get it to filter more than one thing at any one time:

'Flange Rating
pressure = sh2.Range("C5").Value

If pressure > 0 And < 150 Then
sh1.Columns("Y").AutofilterMode = False 'Shows all ratings if pressure is < 150
ElseIf pressure > 150 And pressure < 300 Or pressure = 300 Then
sh2.Range("A2").AutoFilter 25, "300" And "600" And "900" And "1500" And "2500" 'Filters everything below 300 out
ElseIf pressure > 300 And pressure < 600 Or pressure = 600 Then
.....

Any help is much appreciated!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Maybe
Code:
sh1.Range("A1:Y1").AutoFilter 25, ">=" & sh2.Range("C5")
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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