Some possible enhancements to the basic idea:
Sub Tester5()
Dim s, t, u, v, s1, t1, u1, v1
s = "123ABC": s1 = retText(s)
t = "ABC 456": t1 = retText(t)
u = "12 A 56 B": u1 = retText(u)
v = "abcdefgh": v1 = retText(v)
Debug.Print s, s1
Debug.Print t, t1
Debug.Print u, u1
Debug.Print v, v1
End Sub
Function retText(var)
retText = ""
If VarType(retText) = 8 Then
If Not IsNumeric(Left(var, 1)) Then
retText = Left(var, IIf(InStr(1, var, " ") = 0, _
Len(var), InStr(1, var, " ")))
End If
End If
End Function
Returns
ABC 456 ABC
12 A 56 B
abcdefgh abcdefgh
--
Regards,
Tom Ogilvy
Vasant Nanavati said:
Something like:
If Not IsNumeric(Left(var, 1)) Then newvar = Left("b34 s", InStr(1, var, "
") - 1)
This assumes that the variable "var" always contains a space if it begins
with a letter.