Hello, if you want to do this in a worksheet, I think I would use Aladin's worksheet function over a vba udf.
But if you wanted to do this in VB for whatever reason, I might be tempted to stack a byte array and use it like:<font face=Courier New><SPAN style="color:darkblue">Function</SPAN> AddInp(myStr<SPAN style="color:darkblue">As</SPAN><SPAN style="color:darkblue">String</SPAN>)<SPAN style="color:darkblue">As</SPAN><SPAN style="color:darkblue">Integer</SPAN><SPAN style="color:darkblue">Dim</SPAN> b()<SPAN style="color:darkblue">As</SPAN><SPAN style="color:darkblue">Byte</SPAN>, z<SPAN style="color:darkblue">As</SPAN><SPAN style="color:darkblue">Integer</SPAN>, i<SPAN style="color:darkblue">As</SPAN><SPAN style="color:darkblue">Integer</SPAN>
b = myStr<SPAN style="color:darkblue">For</SPAN> i =<SPAN style="color:darkblue">LBound</SPAN>(b)<SPAN style="color:darkblue">To</SPAN><SPAN style="color:darkblue">UBound</SPAN>(b)<SPAN style="color:darkblue">Step</SPAN> 2
z = z + Val(ChrW$(b(i)))<SPAN style="color:darkblue">Next</SPAN>
Erase b
AddInp = z
z =<SPAN style="color:darkblue">Empty</SPAN><SPAN style="color:darkblue">End</SPAN><SPAN style="color:darkblue">Function</SPAN><SPAN style="color:darkblue">Sub</SPAN> test()
MsgBox AddInp("76432")
MsgBox AddInp("764 32")
MsgBox AddInp("764 test 32")<SPAN style="color:darkblue">End</SPAN><SPAN style="color:darkblue">Sub</SPAN></FONT>
I use the val statement to compensate for non numerical characters in your string. You could use it in a worksheet like:
But again, I might stick with the native functionality presented earlier unless you have text characters in your string.