Sunday, 9 December 2012

Excel VBA Macro To Sum The Individual Digits of Number

Excel VBA Macro To Sum The Individual Digits of Number

'Suppose In Column 'A' having Numbers Then You Can find the Sum of Individual Digits of Numbers in Column 'B'
'Eg: A1=147 then B1=1+4+7=11 will return.

Sub SumDigitz()
Dim i As Integer
Dim j As Integer
For i = 1 To 100 'Rows Having Numbers

Cells(i, 2).Clear
If Cells(i, 1) = "" Then Exit For

For j = 1 To Len(Cells(i, 1))
Cells(i, 2) = Cells(i, 2) + Mid(Cells(i, 1), j, 1)
Next j

Next i
End Sub


No comments:

Post a Comment

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts