After weeks of struggling to get this blog upgraded to the latest version of WordPress, it’s finally up and going again. I’ve had to constantly engage in hand-to-hand combat with WordPress over the last few months. I think I’ve beat it into submission, but who knows what nonsense will pop up next. I’ve come very close to completely closing up shop and becoming a monk.
But enough complaining. Back to business.
Erin (One of my 12 fans) asked me to explain the MOD function. She says:
“I’ve see MOD used in one form or another and I just take for granted that it works. But what does it exactly do?”
The Basic Concept behind MOD
MOD is actually Excel’s name for a mathematical term – Modulo. A Modulo is the integer-based representation of the remaining number of units after performing a division operation.
Let’s use some Excel shape art to help illustrate.
Say that I have 8 pieces of bacon. If wake up only one of my kids for breakfast, he’ll get all eight pieces. There are no pieces of bacon remaining, so the modulo is zero. In Excel, you could write this as =MOD(8,1).
If I woke up two of my kids for breakfast, they would share the 8 pieces of bacon – each kid gets 4 pieces. Again, all eight pieces are evenly distributed so there are zero pieces of bacon remaining. In Excel, the formula =MOD(8,2) would indeed return 0.
Now let’s say I woke up three of my children, forcing them to share 8 pieces of bacon. In this case, I can’t evenly distribute the bacon. Two children could have three pieces each, but that leaves a modulo of two pieces for the last monster. Anyone who has more than one child knows that this scenario is the start of a damned fight. So no…I don’t think I’ll invite that that third child to breakfast. MOD(8,3) = 2
At the risk of beating the point to the ground, let’s do one more. Inviting five children to breakfast ensures that each child gets one piece of bacon, leaving a modulo of three pieces.
Those three pieces go to me. After all, I’m the one that cooked the stupid bacon.
Understanding the Math
Although you can use the pre-canned MOD function in Excel, it is useful to know the math behind MOD.
A commonly used alternative expression for getting to a modulo is:
Will give the same result as
Clever Uses for the MOD Function
I’ve see the MOD function is used in all kinds of clever ways over the years.
You’ll often see this inconspicuous function in formulas, conditional formatting, and even VBA.
Here is just a sampling of nifty things you can do with the MOD function.
Count cells that contain odd numbers
Calculate which date Easter falls on
Conditionally Format or highlight every Nth row
Calculate Total Time Worked across AM and PM hours
Calculate Payroll Penalty for Every 15 Minute Increment Late
Check if a value is a Prime Number
So there you go. I hope this quick view into the MOD function changed your life. Or at least gave you a craving for bacon.