Well, you've asked two different questions.
I have three kids: DS25, DS20, and DD18. DS25 is finishing his BBA next week from an in-state public university. DS20 is on a COVID / maturity break from an out of state private school where he's a sophomore seeking a BSME. DD18 just finished their first semester at an in state public university seeking a BA in music education; they're approximately a sophomore.
I did much as @dak2018 did. I picked an amount as a goal (in my case 4 years of public university tuition/fees/room/board/books/necessities per kid) and saved up enough in their 529s to hit that amount after accounting for growth and using up the accounts when they were getting their degrees.
As they have gotten closer and firmed up their plans, I've gradually shifted my spreadsheet from reflecting a generic 4 year university to reflecting their specific university timing and costs. This has honestly caused some major swings, as my oldest went from a full ride scholarship to paying OOP for school 1, then stopping out for a few years and working, to going back and finishing at school 2. DS20's out of state school is expensive, but he gets a big scholarship and a lot of financial aid from the school. DD18 was free at their first school but is talking about transferring to an out of state public which could cost an extra $120K net OOP.
So my summary answer to your first question is: (1) pick a reasonable number as a target, (2) fund toward that target, (3) be ready to be flexible.
For the second question of what to do with excess, there are several answers:
The first simple defense is shifting money between accounts. My kids 529s are all from my home state, and so I can move money between them very easily. While each of them has followed very different paths with different timing and different costs, it turns out that the average of the three kids' plans approximately will end up close to my original funding target.
The second defense is leaving the leftover money in the 529 and using it for education expenses after your three kids finish their undergrad degrees. They could use it for graduate degrees. You could use it for another degree for you or your partner. It could be a head start on your grandchildren's educations. If you're generous, you could gift or sell it to your nieces and nephews for their educations (if they go to college after your kids do).
A third defense is scholarships. If your kid gets scholarships (or goes to a military academy), then you can take money out of the 529 and only pay income taxes on the gain (so it ends up acting sort of like a traditional IRA in that way).
A fourth defense is just to withdraw the excess. You'll pay income taxes plus a 10% penalty, but only on the portion of the withdrawal that is a gain. While I try to avoid penalties, if you do the math this actually isn't that bad.
A fifth defense it to wait and make sure they're not going to use it. Currently my DD18 is literally getting paid to go to school - they have 8 scholarships and they sent her two checks totaling a few thousand dollars which was the excess of the scholarships over their fall school billing statement. And that ignores any COVID payments that they got. Figuring that into my plan, I thought I had overfunded 529s. However, as noted above, DD18 wants to switch to a different (out-of-state) school, which may increase our OOP costs by $120K or so. That extra $120K will sop up any excess/overfunding I thought I had in their 529s. If that happens, I'll use up the 529s and then switch to my contingency plans for "What do I do if I don't have enough in their college funds?"
One trick we're doing with my oldest son: He has some excess 529 money and wants to put it towards a house down payment. Since he is graduating this year and has been a poor college student this year with basically zero income, we made the excess withdrawal last month. He won't owe the 10% penalty because he had enough in scholarships to use the scholarship exemption. And he basically won't owe any income taxes on the withdrawal because the amount is under his standard exemption. So effectively a tax free withdrawal. If he had made the withdrawal next year, then it would have been piled on top of his wage income from his job and he may have owed 22% income tax on the 529 withdrawal.
So the trick here is to make any excess 529 withdrawal in the fall before they graduate, when their income tax situation is likely to be better than when they start their job.