ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Function in XL or in VBA for XL that pulls numeric digits from a t (https://www.excelbanter.com/excel-discussion-misc-queries/1855-re-function-xl-vba-xl-pulls-numeric-digits-t.html)

Nate Oliver

Function in XL or in VBA for XL that pulls numeric digits from a t
 
Hello,

Does XL and/or VBA for XL and/or anyone have any similar function that would
work in XL? If so, I would like to have knowledge of it.


While this thread is somewhat dated, another potential approach is to use a
byte array. E.g.,

Function retNumeric(ByVal myStr As String) As Double
Dim b() As Byte, i As Long, myNum As String
b = StrConv(myStr, vbFromUnicode)
For i = LBound(b) To UBound(b)
Select Case b(i)
Case 46, 48 To 57
myNum = myNum & ChrW$(b(i))
End Select
Next
retNumeric = myNum
End Function

Sub tester()
MsgBox retNumeric("A123B456C789")
End Sub

You can change the ASCII chars and function data type to adjust the parsed
return.

Regards,
Nate Oliver


All times are GMT +1. The time now is 12:40 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com