Thursday, October 20, 2011

UDF to find the smallest numeric value in a string or text

If you want to find the smallest numeric value in a cell. Snapshot below-


Here is the UDF to extract the smallest numeric value .

Function Minval(x As String)
Dim i As Integer, minx As Integer
For i = 1 To Len(x)
If IsNumeric(Mid(x, i, 1)) Then
minx = Mid(x, i, 1)
Exit For
End If
Next
For i = 1 To Len(x)
If IsNumeric(Mid(x, i, 1)) Then
If Mid(x, i, 1) < minx Then
minx = Mid(x, i, 1)
End If
End If
Next i
Minval = minx
End Function

Type in B2 "=Minval(A2)"

No comments:

Post a Comment

Import data from SQL

Macro to import data from SQL using ADO connection string: Sub Import_data_from_SQL() ' Tools -> References -> Microsoft Active...