Extract first instance of two-character string between underscores

mnyankee

New Member
Joined
Mar 20, 2023
Messages
15
Office Version
  1. 365
Platform
  1. Windows
I need help writing a formula that will search a string and return the first instance of two characters only, between two underscores. Probably not explaining that well but my examples are:

abcd_ef_gh_ijkl this should return ef
abc_efgh_ijk_lm_nop this should return lm

My current formula: =MID(A2,FIND("_",A2,1)+1,FIND("_",A2,FIND("_",A2,1)+1)-FIND("_",A2,1)-1)

is only returning the characters between the first two underscores. Is there a formula that will do what I am asking?
 
I wish I had learned RegEx long ago. I tried but it just wouldn't sink in so I'm stuck with more code for the same thing. I think I was able to solve it with a function as I began with the first character after the first underscore so it didn't grab the first 2 characters.
 
Upvote 0
Is that correctable?
To answer that question: Yes, though of course the SEARCH & REGEX ones are still a bit simpler.

25 03 06.xlsm
AB
1
2abcd_ef_gh_ijklef
3abc_efgh_ijk_lm_noplm
4ab_cde_fg_hifg
5a_bcd_e_fg_hfg
6_abc_de_fg_hide
Find _.._
Cell Formulas
RangeFormula
B2:B6B2=LET(s,TEXTSPLIT(111&A2,"_"),TAKE(FILTER(s,LEN(s)=2),,1))



I asked ChatGPT before posting my question and it was nowhere near the correct solution.
That is a fairly common situation between Excel and ChatGPT. :cool:
 
Upvote 0

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