Extract specific string of text from cell

CF64

Board Regular
Joined
Feb 17, 2021
Messages
50
Office Version
  1. 365
Platform
  1. Windows
Hello,
I have a column of cells which contains strings of text separated by line breaks.
Is there a formula which I could use to find a string which starts with specific text and pull that string into the adjacent cell?
For example, in the table below "Massachusetts:..." appears in multiple cells with a different city after the ":"
Is there a formula to enter in the adjacent cell in Column B which searches for "Massachusetts:" and returns the entire string (i.e. Massachusetts: City) regardless of which line it appears on in each cell in Column A?
Thank you for your consideration of my question

Column AColumn B
Massachusetts: Boston
Connecticut: Hartford
California: Los Angeles
Massachusetts: Boston
Connecticut: New Haven
California: San Diego
Massachusetts: Boston
Massachusetts: Boston
Connecticut: Hartford
California: Sacramento
Massachusetts: Salem
Massachusetts: Salem
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
How about
Excel Formula:
=FILTERXML("<k><m>"&SUBSTITUTE(A2,CHAR(10),"</m><m>")&"</m></k>","//m[starts-with(.,'Mass')]")
 
Upvote 0
You're welcome & thansk for the feedback.
 
Upvote 0
May I please ask 2 follow up questions?
Using the formula above, is there a way to just pull the text which is after the colon instead of he entire string?

If I have a cell in column A that has multiple "Massachusetts:...", how would I get both to appear in the cell in column B? Using the formula above I get a Spill error
Column AColumn B
Massachusetts: Boston
Connecticut: Hartford
California: Los Angeles
Massachusetts: Boston
Connecticut: New Haven
Massachusetts: Salem
Massachusetts: Boston
Massachusetts: Boston
Massachusetts: Salem
Connecticut: Hartford
California: Sacramento
Massachusetts: Salem
Massachusetts: Salem
 
Upvote 0
For both values try.
Excel Formula:
=TEXTJOIN(CHAR(10),,FILTERXML("<k><m>"&SUBSTITUTE(A2,CHAR(10),"</m><m>")&"</m></k>","//m[starts-with(.,'Mass')]"))
 
Upvote 0
For both values try.
Excel Formula:
=TEXTJOIN(CHAR(10),,FILTERXML("<k><m>"&SUBSTITUTE(A2,CHAR(10),"</m><m>")&"</m></k>","//m[starts-with(.,'Mass')]"))
Thank you!
 
Upvote 0
If anyone knows a way to just pull the text which is after the colon instead of he entire string using the same formula would be greatly appreciated.
 
Upvote 0
Thought I'd posted that, but how about
Excel Formula:
=TEXTJOIN(CHAR(10),,FILTERXML("<k><m>"&SUBSTITUTE(SUBSTITUTE(A2,CHAR(10),"</m><m>"),":","</m><m>")&"</m></k>","//m[starts-with(.,'Mass')]/following::m[1]"))
 
Upvote 0
Solution
content removed

Sorry about that
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,350
Messages
6,171,590
Members
452,412
Latest member
sprichwort

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