/targetenemy issue

Hello everyone.

I am trying to build a macro for fast targeting without using Tab(which cycles through targets but not always good targets)

So if i am using:
/cleartarget
/targetenemy
/use (whatever spell here)

this targets exactly the target in front of me, near or far and if i change my camera angle, it switches to a different target in front of me. This works perfect, as long as there is no caster enemy anywhere close. Why does /target enemy focuses on the caster all of the sudden? Can i write a condition to ignore the caster and just focus on whatever mob is in front? Or is there another /target(no condition)enemy functionality i can use?

(Sorry if this is a repost)
There isn't a macro conditional to check the type of mob to target. If you are struggling with the new tab targeting there are addons which will turn it back to how it was pre-legion, or you could try using the "target scan enemy (hold)" option in the standard keybinds menu. Personally I only ever use tab targeting unless there is only 1 target available because of how unreliable it is. I much prefer just clicking on the health bars instead.