Using VBA to filte where criteria is variable

jfabro

New Member
Joined
May 25, 2014
Messages
10
Hello again,
I am attempting to filter a file using VBA and the criteria will vary each time the macro is run. Also once filtered I will need to select the filtered cells and delete the rows, of course the range will vary depending on the filter criteria.
Is there a way to write code for this?

Thank you for your assistance.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Re: Using VBA to filter where criteria is variable

Hello again,
I am attempting to filter a file using VBA and the criteria will vary each time the macro is run. Also once filtered I will need to select the filtered cells and delete the rows, of course the range will vary depending on the filter criteria.
Is there a way to write code for this?

Thank you for your assistance.

I am working with a spreadsheet to produce a report. The data will vary depending on the department for which I am reporting. I need to select the records in column A that are the result of a filter and paste them in column B, once pasted I need to clear the cells in column A then remove the filter. I have been able to accommodate the variable criteria for the filter; however, my problem is with selecting the variable range. The data to be selected will never start in cell A2, any cell after that is fair game. How do I select a range that varies? How do I have the User interact with the macro to select the cells?</SPAN>
This works for me to filter by all my variables.</SPAN>
Cells.Select</SPAN>
Selection.AutoFilter</SPAN>
ActiveSheet.Range("$A$1:$F$65000").AutoFilter Field:=1, Criteria1:=Array( _</SPAN>
"1000", "1001", "1005", "ZBIL", "1002", "1003", "1004", "1006", "1007", "1008", "1009", "AOMS", "ASPS", "NATL", "ZCON", "ZREP"), Operator:=xlFilterValues</SPAN>
On Error Resume Next

I am using the following to select the range, the first line works to select the data to be copied (although it still selects the cell A1 and I would prefer not to have that cell selected). The second line returns an error "Object doesn't support this property or method. I have tried range select ToRight however I end up with the entire sheet selected.

Range(ActiveCell, ActiveCell.End(xlDown)).Select
Selection(Selection, Selection.xlToRight).Select
</SPAN> Selection.FillRight

I appreciate any assistance that is available.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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