Formula to extract upper case words in a text string

spbcson

New Member
Joined
Feb 11, 2013
Messages
15
IS THERE A FORMULA TO EXTRACT A UPPER CASE FROM A TEXT STRING IN A CELL? Example in cell A1 i have this text string:
//-- y MICROSOFT EXCEL computer software June 23489​

How can I get only the words "MICROSOFT EXCEL"
 
I'm not 100% sure of the construction of all the possible text that would need to be processed, but this modification to my code (note that I changed the function's name) works for the two examples you posted...
VBA Code:
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
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Wow its works like champ. Thanks a lot Rick, it was exactly that I was searching for! :)
 
Upvote 0
A more direct approach UDF that you could also consider. Note also this returns different results to the UpText UDF depending on the particular data that you may or may not encounter and the exact results that you would expect (see rows 3 & 4 below). (I know that you didn't mention the "-" as a possibility but I wondered if that may be possible.)
What result would you want if A4 of my sample data is possible?

VBA Code:
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
ABC
1Receive 10000 P.I.E INDUSTRIAL at 3.220 per lotP.I.E INDUSTRIALP.I.E INDUSTRIAL
2Send 2200 D&O GREEN TECH at 5.900 per lotD&O GREEN TECHD&O GREEN TECH
3Send 100 X BOX INDUSTRIAL at 35 per lotX BOX INDUSTRIALBOX INDUSTRIAL
4Send 100 X-BOX INDUSTRIAL at 35 per lotX-BOX INDUSTRIALBOX INDUSTRIAL
Sheet1
Cell Formulas
RangeFormula
B1:B4B1=UCtext(A1)
C1:C4C1=UpText(A1)
 
Upvote 0
Note also this returns different results to the UpText UDF depending on the particular data that you may or may not encounter
I deliberately excluded single upper case letters in case there was text like this (completely made up example)...

Send A 4 X 6 Photo Of 100 X-BOX INDUSTRIAL At 35 Per Lot

I also completely qualified my response as to the type of data that the function was to process because I felt two examples were not really enough to go on.
 
Upvote 0
I meant no criticism at all of your results Rick, just offering an alternative, & prodding again about possible different data. :)
 
Upvote 0
Peter... I did not take your post as a criticism, rather, I thought it might be useful to the OP to understand why I wrote my code the way I did and where your suggestion might cause a problem if the general text strings he had to deal with could have single upper case letters elsewhere in the text. My last sentence was really meant for the poster and not you per se... two examples is really not enough to form an answer for that one can be confident in.
 
Upvote 0
@Peter, nice Regex! I was wondering, is the part in red necessary? It seems to work without aswell. Just curious!

[^ ]*[^A-Z\.& \-][^ ]*(?= |$)
 
Upvote 0

Forum statistics

Threads
1,216,172
Messages
6,129,292
Members
449,498
Latest member
Lee_ray

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top