Extract multiple words that contain certain characters

XL User

New Member
Joined
Apr 11, 2018
Messages
8
Hi all,

Need help with the above concern. Here is an example data source:

[TABLE="width: 324"]
<colgroup><col></colgroup><tbody>[TR]
[TD]PS1001 TX1001 TX1001 PS1001 SECTION BE 4 12 S[/TD]
[/TR]
[TR]
[TD]PS1001 TX1001 TX1001 PS1001 SECTION BE 4 12 S[/TD]
[/TR]
[TR]
[TD]PS1001 TX1001 TX1001 BS1001 SECTION BE 4 12 S[/TD]
[/TR]
[TR]
[TD]PS1001 TX1001 TX1001 PS1001 SECTION BE 4 12 S[/TD]
[/TR]
[TR]
[TD]PS1001 TX1001 TX1001 PS1001 SECTION BE 4 12 S[/TD]
[/TR]
[TR]
[TD]PS1001 TX1001 TX1001 PS1001 SECTION BE 4 12 S[/TD]
[/TR]
[TR]
[TD]PS1001 TX1001 TX1001 PS1001 SECTION BE 4 12 S[/TD]
[/TR]
</tbody>[/TABLE]

I want to extract all words which contain PS, or TX into one separate cell. Below are the formulas I have already tried:

=TRIM(MID(SUBSTITUTE(B11," ",REPT(" ",99)),MAX(1,FIND("PS",SUBSTITUTE(B11," ",REPT(" ",99)))-50),99))

=CONCATENATE(IFERROR(TRIM(LEFT(SUBSTITUTE(MID(B7,FIND("~~",SUBSTITUTE(B7,"PS","~~",1)),LEN(B7))," ",REPT(" ",100),1),100)),""),",",IFERROR(TRIM(LEFT(SUBSTITUTE(MID(B7,FIND("~~",SUBSTITUTE(B7,"TX","~~",2)),LEN(B7))," ",REPT(" ",100),1),100)),""),",",IFERROR(TRIM(LEFT(SUBSTITUTE(MID(B7,FIND("~~",SUBSTITUTE(B7,"BS","~~",3)),LEN(B7))," ",REPT(" ",100),1),100)),""))

None seems to be working properly... Please help
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Is the example your provided a representative data, meaning it contains all the possible variations in your data? If not, people might come up with a formula that works on this particular example but may not work on other examples that you did not post.
 
Upvote 0
Hi,

Great point by yky, please give some Real examples of your data, the ones you posted are identical, how would that be?

The example formulas you posted are not relevant to your data, especially the 2nd one.
 
Upvote 0
B1=IFERROR(INDEX(TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",99)),ROW($1:93)*99-98,99)),SMALL(IF(MMULT(--ISNUMBER(FIND({"PS","TX"},TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",99)),ROW($1:93)*99-98,99)))),{1;1})>0,ROW($1:93)),COLUMN(A1))),"")

please use Ctrl+Shift +Enter to run the formula

Copy formula to column C, D......untile formula returns "".
 
Upvote 0
Thanks guys

Yes begins with PS or TX.

Basically, I need to show all words from a cell into another single cell based on a list of specific prefixes:

[TABLE="width: 192"]
<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl65, width: 192, colspan: 3"]PREFIX[/TD]
[/TR]
[TR]
[TD="class: xl66"]PS[/TD]
[TD="class: xl66"]PX[/TD]
[TD="class: xl66"]PT[/TD]
[/TR]
[TR]
[TD="class: xl66"]TS[/TD]
[TD="class: xl66"]TX[/TD]
[TD="class: xl66"]TT[/TD]
[/TR]
[TR]
[TD="class: xl66"]HS[/TD]
[TD="class: xl66"]HX[/TD]
[TD="class: xl66"]HT[/TD]
[/TR]
[TR]
[TD="class: xl66"]BS[/TD]
[TD="class: xl66"]BX[/TD]
[TD="class: xl66"]BT[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Code:
=IFERROR(INDEX(TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",99)),ROW($1:93)*99-98,99)),SMALL(IF(MMULT(--ISNUMBER(FIND({"PS","PX","PT","TS","TX","TT","HS","HX","HT","BS","BX","BT"},TRIM(MID(SUBSTITUTE($A1," ",REPT(" ",99)),ROW($1:93)*99-98,99)))),ROW(1:12)^0)>0,ROW($1:93)),COLUMN(A1))),"")
row(1:12) means there are 12 prefixes, if you have more, please update 12 to other numbers.
 
Upvote 0
If all the words begin with PS or TX, there is a another formula will work:
Code:
=IFERROR(TRIM(LEFT(SUBSTITUTE(MID($A1,SMALL(IF(MID(" "&$A1,ROW($1:99),3)={" PS"," TX"},ROW($1:99)),COLUMN(A1)),99)," ",REPT(" ",99)),99)),"")
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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