Answer
(Fatwa: 1746/1665=D/1429)
If Hajj is obligatory upon you, you should do Hajj first, for it is makrooh tahrimi (undesirable to an extent of haram) for a person to do Hajj Badal on behalf of other when Hajj is obligatory on himself. If Hajj is not obligatory because of not having money, it is makrooh (only) for you to go on Hajj Badal on behalf of your grandfather, it is better for those to go on Hajj Badal who have already performed their Hajj. In both the cases, whether Hajj is obligatory upon you or not, if you go on Hajj Badal from your grandfather, the Hajj will be valid but you will be sinful; more in first case and less in second case.
Allah (Subhana Wa Ta’ala) knows Best
Darul Ifta,
Darul Uloom Deoband