Macro to filter based on a range

jasonfish11

Board Regular
Joined
May 14, 2015
Messages
53
All,
I'm trying to filter items on a sheet based on a range of data that gets input from another sheet. My current macro is only filtering based on the 1st cell in that range.
The range I'd like it to filter based on will change day to day. Some days it may be 3 items some days it may be 7. So I am not able to just have the filter look at 4 specific cells.
Here is what I currently have and I am not sure why it isn't filtering based off all 4 cells, instead it is only filtering based on the 1st cell in that range.

Code:
[COLOR=#00008B][FONT=Consolas]Dim[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] POinput [/FONT][/COLOR][COLOR=#00008B][FONT=Consolas]As[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] Range[/FONT][/COLOR][COLOR=#000000][FONT=Consolas],[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] cell [/FONT][/COLOR][COLOR=#00008B][FONT=Consolas]As[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] Range
[/FONT][/COLOR]
Code:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">[COLOR=#00008B]Dim[/COLOR][COLOR=#000000] lrow [/COLOR][COLOR=#00008B]As[/COLOR][COLOR=#00008B]Integer[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#00008B]Dim[/COLOR][COLOR=#000000] arrList[/COLOR][COLOR=#000000]()[/COLOR][COLOR=#00008B]As[/COLOR][COLOR=#00008B]String[/COLOR][COLOR=#000000],[/COLOR][COLOR=#000000] lngcnt [/COLOR][COLOR=#00008B]As[/COLOR][COLOR=#00008B]Long[/COLOR][COLOR=#000000]

[/COLOR][COLOR=#00008B]With[/COLOR][COLOR=#000000] Sheets[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]"Control"[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
    lrow [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] Range[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]"A50"[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#00008B]End[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]xlUp[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#000000]Row
    [/COLOR][COLOR=#00008B]Set[/COLOR][COLOR=#000000] POinput [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Range[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]"A5:A"[/COLOR][COLOR=#000000]&[/COLOR][COLOR=#000000] lrow[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#00008B]End[/COLOR][COLOR=#00008B]With[/COLOR][COLOR=#000000]

lngcnt [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#800000]0[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#00008B]For[/COLOR][COLOR=#00008B]Each[/COLOR][COLOR=#000000] cell [/COLOR][COLOR=#00008B]In[/COLOR][COLOR=#000000] POinput
    [/COLOR][COLOR=#00008B]ReDim[/COLOR][COLOR=#00008B]Preserve[/COLOR][COLOR=#000000] arrList[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]lngcnt[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
    arrList[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]lngcnt[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] cell[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Text
    lngcnt [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] lngcnt [/COLOR][COLOR=#000000]+[/COLOR][COLOR=#800000]1[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#00008B]Next[/COLOR][COLOR=#000000]


Sheets[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]"ACTOpenItems"[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#00008B]Select[/COLOR][COLOR=#000000]
    ActiveSheet[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Range[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]"A1:FH"[/COLOR][COLOR=#000000]&[/COLOR][COLOR=#000000] lastrow[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#000000]AutoFilter Field[/COLOR][COLOR=#000000]:=[/COLOR][COLOR=#800000]2[/COLOR][COLOR=#000000],[/COLOR][COLOR=#000000] Criteria1[/COLOR][COLOR=#000000]:=[/COLOR][COLOR=#000000]arrList[/COLOR][COLOR=#000000],[/COLOR][COLOR=#000000] _ [/COLOR]</code>[FONT=Helvetica Neue][COLOR=#000000][FONT=Consolas]                                                    Operator[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]:=[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]xlFilterValues[/FONT][/COLOR][/FONT]


I could do this manually with a filter, but this is just 1 step in a process I'm trying to automate using VBA. I could run one macro then have the preparer auto filter then run a 2nd macro but I was hoping to find a way to have the macro do the filter for me based on a range the preparer creates at the beginning of the process.

Thank you in advance for your help.

*also I am not sure why it is breaking the coding into 2 different boxes. I've tried editing out the extra "[C0DE][/C0DE]" function but when I hit save it just adds them back in.
 
Last edited:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

jasonfish11

Board Regular
Joined
May 14, 2015
Messages
53
Is there any additional information needed from me to help answer this?

I'm stuck and really hoping that I can get this working like I intended.
 
Upvote 0

jasonfish11

Board Regular
Joined
May 14, 2015
Messages
53
I missed a "." in my coding causing the issue.

This
Code:
[COLOR=#00008B][FONT=Consolas]With[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] Sheets[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]([/FONT][/COLOR][COLOR=#800000][FONT=Consolas]"Control"[/FONT][/COLOR][COLOR=#000000][FONT=Consolas])
[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]    lrow [/FONT][/COLOR][COLOR=#000000][FONT=Consolas]=[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] Range[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]([/FONT][/COLOR][COLOR=#800000][FONT=Consolas]"A50"[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]).[/FONT][/COLOR][COLOR=#00008B][FONT=Consolas]End[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]([/FONT][/COLOR][COLOR=#000000][FONT=Consolas]xlUp[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]).[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]Row[/FONT][/COLOR]

Should have been this:
Code:
[COLOR=#00008B][FONT=Consolas]With[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] Sheets[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]([/FONT][/COLOR][COLOR=#800000][FONT=Consolas]"Control"[/FONT][/COLOR][COLOR=#000000][FONT=Consolas])
[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]    lrow [/FONT][/COLOR][COLOR=#000000][FONT=Consolas]=[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] [/FONT][/COLOR][COLOR=#ff0000][FONT=Consolas][B].[/B][/FONT][/COLOR][COLOR=#000000][FONT=Consolas]Range[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]([/FONT][/COLOR][COLOR=#800000][FONT=Consolas]"A50"[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]).[/FONT][/COLOR][COLOR=#00008B][FONT=Consolas]End[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]([/FONT][/COLOR][COLOR=#000000][FONT=Consolas]xlUp[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]).[/FONT][/COLOR][COLOR=#000000][FONT=Consolas]Row[/FONT][/COLOR]
 
Upvote 0

Forum statistics

Threads
1,195,938
Messages
6,012,416
Members
441,698
Latest member
DaveTeo

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
Top