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.
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.
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: