How to specify exploration "Apply to" filter using AFL

Is it possible to specify the filter programmatically, rather than selecting it in the GUI?
I am looking for a better way than this:

if( MarketID(1) == "Undefined" )
CategoryAddSymbol( "", categoryMarket, 5 );

This works but it is slow because it has to comb through the entire database instead going directly to selected filtered group like in the GUI.
Any ideas?

You should store ANALYSIS PROJECT (.APX file) via File->Save As instead of just using AFL file. Analysis project contains everything: formula, settings and Apply To/ Range settings. That way you don't need to do anything. Just load analysis project and everything is set up and ready to run.