I'm totally stumped on why this isn't returning a value. This set of functions is supposed to return the SUM of all the ASCII values in a String. The String and Number arrays build properly and the SUM function works on the Array, however when it tries to assign that summed value to the return variable, it fails.
By "it fails" I mean that the code does not step to the sum line and the function returns #VALUE! to the worksheet. Everything else checks out in the immediate window and steps through properly until the last line. Any suggestions are appreciated.
Private Function StringToCharArray(ByRef sIn As String) As String()
StringToCharArray = Split(StrConv(sIn, vbUnicode), Chr(0))
'provided by Fencliff at http://www.mrexcel.com/forum/excel-questions/342725-split-string-into-array.html
End Function
Function StringToNumber(MyString As String) As Integer
Dim StringArray() As String
Dim NumberArray() As Long
StringArray() = StringToCharArray(MyString)
ReDim NumberArray(UBound(StringArray))
For i = LBound(StringArray) To UBound(StringArray)
NumberArray(i) = Asc(StringArray(i))
Next i
StringToNumber = Application.WorksheetFunction.Sum(NumberArray)
End Function
StringToCharArrayfunction should read The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!).