Possible to filter for cell value to be between to given values

mehaffey

New Member
Joined
Oct 25, 2024
Messages
1
Office Version
  1. Prefer Not To Say
Platform
  1. Windows
I have inherited an Excel workbook that has several pages with buttons for macros to filter the data on various sets of criteria. This is the specific code I am working with below and the entire workbook follows the same pattern.
The head of the specific module and the filter code look like this:

VBA Code:
Public Function SetupVariant() As Collection
    Dim allFilters As Collection, Filter As FilterDefinition
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("Variants")
    ' create a main list of filters
    Set allFilters = New Collection

' Test filter
    Set Filter = New FilterDefinition
    Filter.Init "Variants", "Candidates", "Alt Reads > 10, 0.3 < VAF < 0.97"
    Filter.AddCriteria "Alt Reads", ">10"
    Filter.AddCriteria "VAF", Array(">0.03","<0.97")
    allFilters.Add Filter

Obviously the code for AddCriteria Array for >0.03 and <0.97 only shows rows for the <0.97 condition. Is there a way/syntax for Filter.AddCriteria that will do this AND/between logic?

Thank you for your time!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
There's possibly an easier way to go about what you're doing, and we only get to see part of your code & none of your data layout, so the following is just a quick demo of how you would get a 'between' result using Autofilter instead:

Rich (BB code):
Sub Test_Filter()
    With [A1].CurrentRegion
        .AutoFilter 1, ">0.03", xlAnd, "<0.97"
    End With
End Sub

before:
Book1
AB
1HDR1HDR2
20.11data
30.98data
40.20data
50.07data
60.96data
70.13data
80.01data
90.31data
100.50data
111.00data
12
Sheet1


after:
Book1
AB
1HDR1HDR2
20.11data
40.20data
50.07data
60.96data
70.13data
90.31data
100.50data
12
Sheet1
 
Upvote 1

Forum statistics

Threads
1,226,467
Messages
6,191,198
Members
453,646
Latest member
SteenP

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