How to Build a Macro to Create and Save a Filter in Apple Numbers

A pain in the neck with Mac Numbers app is the inability to save complex Filters. They have to be re-created each time. I was wondering if KBM can help.
Could not find anything when I search this forum.
thank you

Hey @ronald,

Please post a sample Numbers file and filter.


1 Like

Thank you Chris.

test Search numbers (51.5 KB)

Hey @ronald,

Unfortunately I don't see any way to do it.

It might be possible to create an analogue of filters using formulas within the sheet itself, but I'm not nearly conversant enough with Numbers to know for sure.


1 Like

Thank very much for giving it some thought.

Do you think he could just create a KM macro that stores the keystrokes needed to create the filter? That idea seems viable to me.

1 Like

thank you. Good idea. I will give it a try

Glad I could help. I create filters in Numbers using keystrokes... and maybe mouse clicks. Keystrokes are the best, so try them first. If you have to use the mouse, macros can get a little messy.

thank you. By keystrokes, do you mean KBM shortcuts (to trigger macros) or native Numbers shortcuts ?

What I meant by keystrokes was using KM actions like "Type Keystroke" to send information to Numbers rather than using the "Move or Click Mouse" action. Most apps allow you to use either the keyboard or mouse to control their functions. KM can handle both cases, but keyboard keys are less complicated to use. Do you need help coming up with a filter using keystrokes?

P.S. I should add that you could consider clicks on the Menu items via KM's Menu Click action to be a third way, but I consider that as keyboard control. Here's an example of that, which will open the Filter tab on the right side of the Numbers app:


Next, since I can't see a menu or keyboard shortcut for "Add a Filter" we might have to resort to a mouse click something like this:


1. So mean using the type keystroke KM action to emulate a numbers menu item which which already has a native keystroke, like turn on filters ⌘⌥F. No problem (if I understand you correctly)

2. The stage at which I am stumped is the following - when the filter menu is open, how to you generate the following filter using a macro ? You can use click on button and insert by typing for the dropdown lists, but how do you generate the filtering rules (lowest image), for example to go from the default Numbers to Text Contains?

Thank you.



I updated my last post, which might help a bit, but I'll try to write the code for the exact filter you are proposing above.

I was already past that stage (just informing you, certainly not being cynical).
Action Press "Add a Filter" button works
next action is insert text by typing → type name of column (fruits in my macro) following by type the keystroke Enter.

It's at the next stage of creating the rule that I am stumped.

I just want to mention that this is just an example using fruits. The actual file I am working on is a large inventory.

thanks again very much

Okay. Don't worry, I enjoy helping. I'll try fro where you indicate you need help.

Okay, I see what you meant by "type name of column" (personally, I would have just pressed the down arrow, but your method also works). Then a new dialog box appears which I've never noticed before when I use numbers. I've used filters before and I've never seen this dialog box. Maybe it's new and improved. I'm tinkering with it now. Sorry that the image is so large, I think it has something to do with my screen resolution.

From the looks of one of your screenshots, your version of Numbers appears to be different from mine, because the dialog boxes don't look the same. So you may not be able to use my solution without some modification. But here's what works for me. Please note that I inserted a "wait 0.5 seconds between each action" at the top, which can be removed once this macro's timing issues, if any, are debugged. This example only adds a single filter, but it may give you the ideas you need to make it work for your own filter. I noticed in your example above you had a filter for "fruit = 2" but I think you made a mistake there because the fruit columns contains only fruit names, not numbers.

You may notice that I used offsets in my Mouse actions. I do this to help guarantee the accuracy of the mouse click actions. There are many ways to solve this and I'm not saying my way is the only way, but I tend to use reliable ways. You may have to change the offsets depending on your monitor's resolution or your screen scaling. But this should give you an idea of how to get it to work.

Group.kmactions (22 KB)

Keyboard Maestro Export

1 Like

Thanks very much!

I will take it from there. Yes, Numbers is different. I think that you have the Monterey 11.2 version. I have the Catalina 11.1. I did not have the courage to upgrade to Monterey so early.

Have you had problems or did the upgrade go smoothly?

I upgraded to Monterey when the Betas first came out (six months ago?) and there were lots of problems then. But by the time it came out officially, I guess those problems had been mostly worked out. But I just installed the official version a week or two ago and haven't had much time to test it.

Glad you liked me advice. That makes me feel happy.

1 Like

thanks !