## sum of digits of a number in vba

REM This function

Public Function digitSum(x As Integer)

Dim I As Integer

Dim SumDigit As Integer

SumDigit = 0

For I = 1 To 10

SumDigit = SumDigit + (x Mod 10)

x = Int(x / 10)

MsgBox "Value of " + I + " value of " + SumDigit

If (x < 1) Then Exit Function

Next I

digitSum = SumDigit

End Function

## Reply

You must be logged in to post a comment.