H
Haggr
the following module produces these results:
(xlb114r returns as xlb1114)
(xs245aaw returns as xs245w) the "W" in this case is important.
but I also need (xan72aa-7.5) to return as (xan72-7.5)
Public Function fGetFirstChars_Nums_w(pString As Variant) As String
On Error GoTo Err_fGetFirstCharsNums
Dim i As Integer
Dim boolNum As Boolean
Dim ch As String
Dim tmp As String
If Len(Trim(pString & "")) > 0 Then
For i = 1 To Len(pString)
ch = MID(pString, i, 1)
Select Case ch
Case "0" To "9"
If boolNum = False Then boolNum = True
tmp = tmp & ch
Case "w"
tmp = tmp & ch
If boolNum = True Then Exit For
Case "-", "/"
'ignore
Case Else
If boolNum = False Then
'no number char yet
tmp = tmp & ch
Else
Exit For
End If
End Select
Next
Else
tmp = vbNullString
End If
fGetFirstChars_Nums_w = tmp
Exit_fGetFirstCharsNums:
Exit Function
Err_fGetFirstCharsNums:
MsgBox Err.Description
Resume Exit_fGetFirstCharsNums
End Function
(xlb114r returns as xlb1114)
(xs245aaw returns as xs245w) the "W" in this case is important.
but I also need (xan72aa-7.5) to return as (xan72-7.5)
Public Function fGetFirstChars_Nums_w(pString As Variant) As String
On Error GoTo Err_fGetFirstCharsNums
Dim i As Integer
Dim boolNum As Boolean
Dim ch As String
Dim tmp As String
If Len(Trim(pString & "")) > 0 Then
For i = 1 To Len(pString)
ch = MID(pString, i, 1)
Select Case ch
Case "0" To "9"
If boolNum = False Then boolNum = True
tmp = tmp & ch
Case "w"
tmp = tmp & ch
If boolNum = True Then Exit For
Case "-", "/"
'ignore
Case Else
If boolNum = False Then
'no number char yet
tmp = tmp & ch
Else
Exit For
End If
End Select
Next
Else
tmp = vbNullString
End If
fGetFirstChars_Nums_w = tmp
Exit_fGetFirstCharsNums:
Exit Function
Err_fGetFirstCharsNums:
MsgBox Err.Description
Resume Exit_fGetFirstCharsNums
End Function