Triggering a Filter using VBA

elio_xh

New Member
Joined
May 17, 2013
Messages
1
I'm creating a macro that automatically creates a Gantt chart and fills in the procedure steps. Since the object I'm tracking is standardized, I have a large database that contains all part numbers and the corresponding procedure steps. My macro first takes in user input to enter the part number, and I'd like it to trigger the filter using the variable that stores the part number.

I've used this code:
Code:
    ActiveSheet.ListObjects("Tracker_AllActiveJobs").Range. _
        AutoFilter Field:=2, Criteria1:=NewPartName
The main problem with this code is that it works fine if there is only one part in the database that matches the "NewPartName" variable, but the majority of the time there will be more than 1 part, with different suffixes or prefixes. So ideally I'd like the filter to search for all parts that have the variable within it's full title.

There was also a second way I could trigger the filter. I created a function so that if you enter the part number in a certain cell and press enter, it would trigger the filter. Here's the code for that:
Code:
Range("B2").Select
    ActiveCell.FormulaR1C1 = NewPartName
The variable "NewPartName" is a string, and when I run the macro it launches the debugger and stops on the the "ActiveCell.FormulaR1C1 = NewPartName" line.

If someone can help me find a way to trigger the filter, that would be awesome. I have no preference to using either of the formulas I've posted, so what ever is easier for you to work with I will implement.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,215,432
Messages
6,124,859
Members
449,194
Latest member
HellScout

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