It's all too easy when making a macro to to fall into the "I'll get KM to emulate what I do" trap. That often means we're playing to our weaknesses rather than KM's strengths and, importantly, we're trying to automate the GUI when we really shouldn't:
set the selected files to none
for each file in the front Finder window
if name contains " Jane" then add it to the selected files
end
move the selected files to a new folder
rename the new folder to "To Delete"
GUI automations are much more fragile than "programmatic" macros -- they usually rely on the GUI being in a known state and can be broken by an accidental mouse click, your email client popping to the front, even an unusual sort order in a window. While you can try and catch many of these it's a lot more, often unnecessary, work.
But programmatically:
get path to folder shown in frontmost Finder window
for each item in that folder
if name contains " Jane" then move to folder "To Delete" in that folder
end for
...which looks very similar to the previous outline. But the important difference is that we only reference the GUI once, in the very first line, which means there's far less chance of something throwing a spanner in the works. You may not even need to do that -- it still feels like you've only presented a small section of a bigger workflow and you could probably determine the path to the frontmost window even earlier in the process and use it throughout.
Enough of the explanation of why this (hopefully!) does what you want but in a different way to how you've stated it -- the above should also help you to adjust it where required. To the macro!
Moving Janes.kmmacros (4.7 KB)