If some of the targets are illegal targets as Gandalf's triggered ability tries to resolve, the original division of damage still applies but no damage is dealt to the illegal targets. If all targets are illegal, Gandalf's triggered ability doesn't resolve.

Artwork
Loading artwork…
Gandalf, Spark Starter
The Hobbit · #97 · EN
Nonfoil—Foil—
Card rules
Reach
When Gandalf enters, he deals 3 damage divided as you choose among one, two, or three targets.
4/3
Gandalf thought of most things; and though he could not do everything, he could do a great deal for friends in a tight corner.
Uncommon · Illustrated by Javier Charro
Format legality
Brawl Legal
Commander Legal
Competitive Brawl Legal
Duel Legal
Future Legal
Gladiator Legal
Historic Legal
Legacy Legal
Modern Legal
Oathbreaker Legal
Pioneer Legal
Standard Legal
Standard Brawl Legal
Timeless Legal
Vintage Legal
Alchemy Not Legal
Old School Not Legal
Pauper Not Legal
Pauper Commander Not Legal
Penny Not Legal
PreDH Not Legal
Premodern Not Legal
Tlr Not Legal
Rulings
Published rulings from the downloaded Scryfall catalog. Source card record · Rules and interactions
You choose how many targets Gandalf's triggered ability has and how the damage is divided as you put the ability on the stack. Each target must receive at least 1 damage.