When you order grouped units to attack, they will attack the unit that is closest to them, regardless of which unit you selected for them to fire on/charge. Ungroup units before attacking with them.