This is discussed in the macros forum.

Basically, what you have to do is work with "/focus charactername".
In a normal situation, the focus of all characters would be set to the main character. Any damage spell would then be typically macroed as "/assist focus /cast spellname".
When your main character dies you simply hit the key that assigns the next-in-line character to be the new main. And so on.
This way you generally only need one type of macro per spell. You do need, however, N-1 keys to assign main characters in a group of N.

Regards.