Saturday 5 August 2017

Sum all digits of a number

Here below find the code to sum all the digits of a number

Subprocedure will ask an input and return a message box of sum.

Sub sum_digits()
num = InputBox("Enter digits to sum")
    Do While Number >= 1
       ss = ss + num Mod 10
        num = Int(num / 10)
    Loop
    MsgBox ss
End Sub



No comments:

Post a Comment