Returning position based values from concatenated string

kidmullet11

New Member
Joined
Oct 17, 2011
Messages
5
I am trying to extract a position based value from a concatenated taxonomy string. Each field in the taxonomy is separated by an underscore, so I essentially want to return the value from the field that consistently appears in say the third position in the string, ie after the second _ and before the third _.

Annoyingly the field length is not always the same (either two or three characters) but it’s position between the second and third underscore is always consistent. Is this even possible? Thanks!
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
It would help if (a) you changed your profile to indicate which version of Excel you use and (b) show a few samples and expected results using XL2BB.
 
Upvote 0
Yes, this is possible.

You need to create an array and then pull the third value from the array

VBA Code:
    Dim varTaxonomy As Variant
    Dim strTaxonomy() As String
    Dim str3rdToxonomy As String
    
    varTaxonomy = Range("A1").Value

    strTaxonomy = Split(varTaxonomy, "_")
  
    str3rdToxonomy = strTaxonomy(2)
 
Upvote 0
If you have TEXTSPLIT:

Book1
ABC
1StringThis is the first field_followed by the second_and then the third_and lastly a fourth string
2
3FieldResult
4One way3and then the third
5Another2followed by the second
Sheet3
Cell Formulas
RangeFormula
C4C4=FILTER(TEXTSPLIT(B1,"_"),{0,0,1,0})
C5C5=INDEX(TEXTSPLIT(B1,"_"),,B5)
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Two other options depending on your version
Excel Formula:
=TEXTAFTER(TEXTBEFORE(A2,"_",3),"_",2)
Excel Formula:
=REPLACE(LEFT(A2,FIND("^",SUBSTITUTE(A2,"_","^",3))-1),1,FIND("^",SUBSTITUTE(A2,"_","^",2)),"")
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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