The only time vitamins for a certain stat will not work is if you already used 10 of them on the pokemon(?) or if that stat's EVs are already maxed out or if your pokemon reached the EV cap.
And other than that it doesn't matter when you use the vitamins on your pokemon