change from message box to result in cell

D

DB

I'm currently running this macro...
**********
Sub Sumcharacters()
Dim i As Long, s As String
Dim lsum As Long
For i = 1 To Len(ActiveCell)
s = Mid(ActiveCell, i, 1)
If IsNumeric(s) Then
lsum = lsum + CLng(s)
End If
Next
MsgBox lsum
End Sub
**********
Instead of the sum showing up in a message box, I'd like the sum to show up
in the next cell over. Can someone help me out on how to do that. I can't
seem to get it to work smoothly.

Thanks
 
L

L. Howard Kittle

Try this

Sub Sumcharacters()
Dim i As Long, s As String
Dim lsum As Long
For i = 1 To Len(ActiveCell)
s = Mid(ActiveCell, i, 1)
If IsNumeric(s) Then
lsum = lsum + CLng(s)
End If
Next
ActiveCell.Offset(0, 1).Value = lsum
End Sub

HTH
Regards,
Howard
 
D

DB

perfect, thank you for the help

L. Howard Kittle said:
Try this

Sub Sumcharacters()
Dim i As Long, s As String
Dim lsum As Long
For i = 1 To Len(ActiveCell)
s = Mid(ActiveCell, i, 1)
If IsNumeric(s) Then
lsum = lsum + CLng(s)
End If
Next
ActiveCell.Offset(0, 1).Value = lsum
End Sub

HTH
Regards,
Howard
 
D

Dave Peterson

You have another response at your original post.
I'm currently running this macro...
**********
Sub Sumcharacters()
Dim i As Long, s As String
Dim lsum As Long
For i = 1 To Len(ActiveCell)
s = Mid(ActiveCell, i, 1)
If IsNumeric(s) Then
lsum = lsum + CLng(s)
End If
Next
MsgBox lsum
End Sub
**********
Instead of the sum showing up in a message box, I'd like the sum to show up
in the next cell over. Can someone help me out on how to do that. I can't
seem to get it to work smoothly.

Thanks
 

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