Howdy and welcome to the board. Yes, it can be done with code. I can reference for you Tom Urtis's solution on pp. 312-314 in the book VBA and Macros for MS Excel by Bill Jelen (MrExcel) et al. Because of copyright issues, I can't post it for you.
BTW, the book is worth its weight in gold if you will do any VBA coding in Excel.