Make VBA filters dynamic with a simple input box for names

Are you looking to enhance your VBA skills by modifying your code to utilize an input box for dynamic filtering?

3 min readMicrosoft Excel | Help & Support with your Formula, Macro, and VBA problems | A Reddit Community

It's a simple ask, make a VBA filter dynamic so a user can type any name into an input box instead of editing code for each new query. And it's exactly the kind of problem that keeps people stuck in manual, repetitive workflows when they don't have to be. The post from u/National_Goat_9792 captures the frustration of hitting a wall with a perfectly reasonable goal: replace a hardcoded string with a variable that comes from user input. The code as written does exactly one thing, for exactly one name. That's not a tool; it's a trap.

The fix itself is straightforward. Instead of `Criteria1:="Name"`, you assign the result of `InputBox("Enter the name to filter:")` to a variable and pass that variable into the filter. VBA's `Application.InputBox` lets you capture text, handle cancellation gracefully, and keep the rest of your filter logic intact. The real insight here isn't the syntax, it's the shift in thinking. You stop writing scripts for a single scenario and start building them for any scenario. That's the difference between a macro that rots in a personal workbook and one you actually ship to a team.

What this means for anyone working in Excel day-to-day is that the barrier between "I have a problem" and "I have a solution" is often just one variable away. The user already knows how to apply an autofilter. They already know how to target a specific field. The missing piece is treating the filter value as something that can change at runtime. Once you internalize that pattern, you stop treating VBA as a fragile record of clicks and start treating it as a lightweight application layer on top of your data.

Our take is this: if you're editing code every time you need to filter a different name, you're doing the work your computer should be doing. The next time you write a filter, build the input box in first. It takes thirty seconds and saves you ten minutes of hunting through modules every week. That's not a revolutionary idea. It's just a better habit.

From Microsoft Excel | Help & Support with your Formula, Macro, and VBA problems | A Reddit Community

I'm trying to figure out how to modify the following VBA code to use an input box for the name instead of hardcoding a specific person's name. Everything I've read and tried hasn't worked. Can someone help?

ActiveSheet.Range("$A$2:$KH$1048576").AutoFilter Field:=59, Criteria1:="Name"

Read the original at Microsoft Excel | Help & Support with your Formula, Macro, and VBA problems | A Reddit Community