First of all, you have all those IFs without ENDIFs...
And, since only one of them should be true, you should use SELECT CASE statements instead.

I assume you use a SUBNET() UDF, but you fail to mention that, nor do you include it or a link to it for us to scrutinize.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.