Q:

Editing Excel Mod Formula

Could you please give me vba code that can solve this problem:
I want remainder in Mod Function can become equal to divisor.
Example: In normal situation Mod(132,12)=0 but I want when remainder is equal to divisor, last step of dividing that is dividing 12 on 12 doesn't do and remainder becomes 12.
Example
I wrote this code but it seems something is wrong. What's the problem?
Function XLMod(a, b)

XLMod = Int(a - (b * Int(a / b)))

If XLMod(a / 10, b) = 1 And XLMod(a, 10) = 2 Then

   XLMod = b

End If

End Function

A:

You need a special exception of the standard modulo function.
If the result of a normal division (a / b) would result in a number ending with 1 (e. g. 1, 31, 10001, 12341, ...), then you want it to return b.
Function XLMod(a, b)
    XLMod = a Mod b
    If XLMod = 0 And (a / b) Mod 10 = 1 Then XLMod = b
End Function

