Sub myMOD2()
Dim RET As Variant
RET = [mod(3,2)] '数値を入れてもOK!
MsgBox RET
End Sub
上記と違い固定値の正の数を入力しているのでmyMOD2を動かすと答えはいつも1
Excelシート関数を使うと難しい数式を考えなくてよい
計算結果をテストする必要がほとんどない
ほぼ全てのExcel関数を使うことができる(引数設定だけ考えればよい)
汎用的に使いたいならプログラムは自作した方が早い
VBA関数として作成する:Function myMOD3
Function myMOD3(a1 As Variant, b1 As Variant) 'As Variant
'ここでのa1,b1はvbaでの変数を指す(セルではない)
myMOD3 = -1 '判定不能
If Not IsNumeric(a1) Then Exit Function
If Not IsNumeric(b1) Then Exit Function
If a1 <= 0 Then Exit Function
If b1 <= 0 Then Exit Function
'計算結果の余りを返す
myMOD3 = a1 - (Int(a1 / b1) * b1)
End Function
Sub test_mymod3()
Dim RET As Variant
RET = myMOD3(10, 3)
MsgBox RET
End Sub