You can combine the IF formula with the ISERROR formula to take care of the error message. For example =(IF(ISERROR(YOURFORMULA),YourFormulaWhenErrorOcurred,YourFormulaWhenItDoesn't)
But I am a bit confused by your example. You say that either AF or AM can be blank, but those values are the upper part of the division and thus won't create the error (0/1=0).
So I'm assuming that either AE, AG or AN can be blank.
Set A formula: =IF(AE2="","",(AF2/AE2)*100)
X formula: =IF(AG2="","",((AF2/AE2)*100)/AG2)
Or combine them in one formula:
Hopefully I understood you correctly and this helps you out.
Do let me know how this works out for you.