VB and VBA Users Source Code: Removing all the non numeric (alpha) characters from a string
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Removing all the non numeric (alpha) characters from a string
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Friday, January 27, 2006
Hits:
10980
Category:
Visual Basic General
Article:
The following function can be used to remove all the non numeric (or alpha characters) from a string. 'Purpose : Removes all non numeric characters from a string. 'Inputs : sNumberToClean The number to remove non numeric characters from. 'Outputs : Returns the input string with the non numeric characters removed. 'Author : Andrew Baker 'Date : 13/11/2000 10:14 'Notes : 'Revisions : Public Function RemoveNonNumeric(sNumberToClean As String) As String Const NUMERIC_CHARS = "0123456789.," Dim lThisChar As Long Dim sResult As String For lThisChar = 1 To Len(sNumberToClean) If InStr(1, NUMERIC_CHARS, Mid$(sNumberToClean, lThisChar, 1)) > 0 Then 'Found a numeric character sResult = sResult + Mid$(sNumberToClean, lThisChar, 1) End If Next 'Return the result RemoveNonNumeric = sResult End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder