How to Calculate the Date and The Number

M

mroks

Guys,

Please help me on how to do the below calculations.

Date (YYDDMM)
080131 = it goes like this 8+1+3+1 = 13 is the answer
Text
1000888 = it goes like this 1+8+8+8= 25 is the answer


Thanks
 
K

Ken Snell \(MVP\)

This function will do what you seek:

Private Function GetSumOfDigits(varData As Variant) As Long
Dim lngPos As Long, lngSum As Long
lngSum = 0
If IsNull(varData) = False Then
For lngPos = 1 To Len(varData)
lngSum = lngSum + Val(Mid(varData, lngPos, 1))
Next lngPos
End If
GetSumOfDigits = lngSum
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top