Substring in the middle of a text string

dmcgimpsey

Active Member
Joined
Mar 30, 2004
Messages
268
Hi Folks, seasons greetings.

I am feeling very lazy today and besides, I want to go and have a smoke.

I am sure someone has already done this before, and I could do it if I convinced myself to get over the procrastinating ... but this is such a great resource for "Tag-Team" programming, I thought I would ask if someone already had some ready made code.

Enough preamble:

What I need is an expression that would extract text from within quotes, somewhere in the middle of a string varaible. There are guaranteed to always be 2 quotes, and there will always be text in the middle.

Example:

<A id=m3_l href="https://mysites.temp/Person.aspx?accountname=ADS%5Cbtname1"/A>

I would like to extract the string:

https://mysites.temp/Person.aspx?accountname=ADS\btname1

I don't wish to have the quotes in the result.

IF someone already has done this, or could give me the code, I would really appreciate it, you would make my day - otherwise, I will have to code it. Writing this post probably took more time than coding it - ha ha... just feeling lazy, hope you understand


Thanks in advance

Don
Merry Xmas
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
sorry, the example is as follows:

(example "Here is the text" and more stuff)


I would like to extract "Here is the text" (without the quotes) and put it in a string.

The string contains HTML so therefore, when I posted it previously, it converted it.
 
Upvote 0
Try

Code:
Sub test()
Dim s As String, X As Variant
With Range("A1")
    X = Split(.Value, Chr(34))
End With
s = X(1)
MsgBox s
End Sub
 
Upvote 0
figured it out .... not as lazy as I thought

pos1 = InStr(1, elem2.innerhtml, """")+1
pos2 = InStr(pos1 + 1, elem2.innerhtml, """")-1
result = Mid(elem2.innerhtml, pos1, pos2 - pos1)
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,140
Members
448,551
Latest member
Sienna de Souza

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