Extract Text From Variable Length String

Marmit424

Board Regular
Joined
Jul 12, 2016
Messages
58
Hi!


I'm trying to extract text from variable strings. Here is a string example:


id="here_is_an_id" name="here_is_a_name" class="here_is_a_class"


I want to extract the text inside name"". However that text length changes, and the fact that it's not the only item in quotes confuses me on how to use the len,mid,search functions. Would someone please help me accomplish this? Thank you so much!
 
Assuming you there will only be one "href" tag per cell, you could use this formula to get the text you want...

=TRIM(REPLACE(LEFT(A1,FIND("<",A1,SEARCH("< a href=",A1)+9)-1),1,FIND(">",A1,SEARCH("< a href=",A1)+9),""))

Edit Note: You must remove the extra spaces after the two highlighted less than symbols.
Minor correction to the above formula... I believe it is possible for there to be Line Feed characters and/or Carriage Return characters within the "href" tag structure. I think this should eliminate them...

=SUBSTITUTE(SUBSTITUTE(TRIM(REPLACE(LEFT(A1,FIND("<",A1,SEARCH("< a href=",A1)+9)-1),1,FIND(">",A1,SEARCH("< a href=",A1)+9),"")),CHAR(10),""),CHAR(13),"")

Edit Note: You must remove the extra spaces after the two highlighted less than symbols.
 
Last edited:
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Rick - see posts #25 and #26. :)
I may have read too much into the question that was asked. If the only thing in the cell is the "href" tag and nothing more, then I would think this formula should work as well...

=REPLACE(LEFT(A1,LEN(A1)-4),1,FIND(">",A1),"")
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,189
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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