Help to develop existing macro, giving one more criteria

bazofio

New Member
Joined
Aug 17, 2012
Messages
11
Hi guys.
I need some help to add a new criteria, if possible, to this macro. What it does now is to when there is some change in some cells it will make a filter to a database to get all the values that match the criterias. Ill try to explain better.....So this is how it works, when one or all the cells "AF2", "AG2" and "AD2" are different then "AF4", "AG4" and "AD4" the macro make the filter in the database (B2:H5000) and gives me the values that match those criteria that is the AF3:AG4 range (values in AF4 and AG4).

What im trying to do is that the macro make the filter searching to match exactly equal the value in AF4 (like its doing now) but in AG4 instead using that value what i need is that macro make the search with a interval, i mean supose that the value is 16, what i want is that it uses this value to search between 14 and 18 (16+2 and 16-2) to give me more results in the end. Because now im limited to a single value to meet the criteria and im getting few results.
Is this possible?
This is my macro:

Code:
Private Sub Worksheet_Calculate()

If Range("AF2") <> Range("AF4") Or Range("AG2") <> Range("AG4") Or Range("AD2") <> Range("AD4") Then
    Application.EnableEvents = False
    Range("AD2:AG2").Value = Range("AD4:AG4").Value
    Range("B2:H5000").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range("AF3:AG4"), _
        CopyToRange:=Range("AH2:AN2"), Unique:=False
    
    Application.EnableEvents = True
End If

Many thanks ;-)
 
This is a sample code in a simple case:
Code:
ActiveSheet.Range("$N$2:$N$10").AutoFilter Field:=1, Criteria1:=">=3", _
        Operator:=xlAnd, Criteria2:="<=5"

However I think it would be best to use the "macro recorder" while manually applying the desired filters.
Then study the recorded macro and figure out exactly what you need.
 
Upvote 0

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