Well, realizing that my "list of things I don't quite understand" is already long enough, and armed with the discovery of "quinn's factor" in A3 and observations of the behavior I had observed when simply adding a column, I decided to have another look, and discovered ... the formulas are all simple, there's no modular arithmetic with MOD(), all quite simple really!
It simply constructs the first day of the month from the Popup choices for month and year and using a day of 1. It figures out what day of the week that is (which depends on q's factor) and also gets the last day of the month. That's it! (Rows 8 through 14 are for the previous month and next month calendars and make it all look more complicated than it is).
Then in the main calendar the "anchor" value in A2 is derived this way:
All that's doing is taking the first-day of the month date and adding (1-the day of the week of the first day of the month).
Then the other cells in the main calendar flow from that anchor value, cells to the right adding a day via =A2+DURATION(0,1), and cells below adding a week via =A2+DURATION(1)
The two little calendars are constructed in the same way. They're all using a "Day Only" custom Data Format.
And there's Conditional Highlighting to "fade out" the cells that are not in that month:
An interesting showcase for the power of Numbers. I find this and some of the other templates deceptively simple. More to them than meets the eye.
SG