The following function returns all letters of a string up to where the value of “-” may be present. For Example, if a string is e345bc-, the function returns e345bc. If a “-” does not exist, the the entire trimmed string is returned.
However, I just noticed that some string values contain a literal *, that is the string can contain a “-” or “*”.
Is there an easy way to modify the function to evaluate for the “-” or “*” so it does the same thing. For example e345- or e345* would return e345?
Function SubC(txt As String) As String
Dim x As Integer
Dim y As Integer
‘Test for “-” in string
‘If “-” Exists, Return String to space prior to “-“, i.e., ABL- is ABL
‘If “-” does not exist, Get entire Trimmed String
For x = 1 To Len(Trim(txt))
If Mid(txt, x, 1) = “-” Then ‘ Does “-” exist
y = x ‘Set Y = to placeholder of “-”
x = Len(txt) ‘Set X to end of loop
SubC = Left(txt, y – 1) ‘Return SubC Value
Exit For
Else:
SubC = Left(txt, x) ‘ If “-” does not exist, return trimmed txt
End If
Next x
End Function