Function UpText(S As String) As String
Dim X As Long, TempText As String, Arr() As String
TempText = " " & S & " "
For X = 2 To Len(TempText) - 1
If Mid(TempText, X, 1) Like "[!A-Z0-9.&]" Or Mid(TempText, X - 1, 3) Like "[!A-Z0-9.&][A-Z0-9.&][!A-Z0-9.&]" Then Mid(TempText, X) = " "
Next
Arr = Split(Application.Trim(TempText))
For X = 0 To UBound(Arr)
If Not Arr(X) Like "*[!0-9.]*" Then Arr(X) = ""
Next
UpText = Application.Trim(Join(Arr))
End Function
Function UCtext(s As String) As String
With CreateObject("VBScript.RegExp")
.Global = True
.Pattern = "[^ ]*[^A-Z\.& \-][^ ]*(?= |$)"
UCtext = Application.Trim(.Replace(s, ""))
End With
End Function
irzam07.xlsm | |||||
---|---|---|---|---|---|
A | B | C | |||
1 | Receive 10000 P.I.E INDUSTRIAL at 3.220 per lot | P.I.E INDUSTRIAL | P.I.E INDUSTRIAL | ||
2 | Send 2200 D&O GREEN TECH at 5.900 per lot | D&O GREEN TECH | D&O GREEN TECH | ||
3 | Send 100 X BOX INDUSTRIAL at 35 per lot | X BOX INDUSTRIAL | BOX INDUSTRIAL | ||
4 | Send 100 X-BOX INDUSTRIAL at 35 per lot | X-BOX INDUSTRIAL | BOX INDUSTRIAL | ||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
B1:B4 | B1 | =UCtext(A1) |
C1:C4 | C1 | =UpText(A1) |
I deliberately excluded single upper case letters in case there was text like this (completely made up example)...Note also this returns different results to the UpText UDF depending on the particular data that you may or may not encounter