Extract 2nd to last word

mozjesse

New Member
Joined
Jul 18, 2008
Messages
4
How do I extract the second to last word from a string of text in one cell and put it another.
 
Examples:
cCTAB_UTyte_2B_HI_LO --> 16
cCTAB_UTyte_1B_HI_LO --> 8
cCTAB_UTyte_3B_HI_LO --> 24
cCTAB_UTyte_4B_HI_LO --> 32
...
Is the lead in text always 12 characters long (as shown)? If so, you can use this slightly simpler formula...

=IFERROR(8*MID(A1,13,1),"")

If the lead in text's length can vary, then is the number always followed by the text "B_HI_LO"? If so, then this slightly simpler formula would work...

=IFERROR(8*MID(A1,LEN(A1)-7,1),"")

If neither of the above is true, then stay with the formula István posted.
 
Last edited:
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Read the 1st character after the second "_" (2) and multiply this value with 8.

Examples:
cCTAB_UTyte_2B_HI_LO
cCTAB_UTyte_1B_HI_LO
cCTAB_UTyte_3B_HI_LO
cCTAB_UTyte_4B_HI_LO
another way

=LEFT(RIGHT(A1,8),1)*8
=LEFT(RIGHT(A1,8),1)*16
....
 
Upvote 0
=trim(left(right(" "&substitute(trim(a1)," ",rept(" ",60)),180),60))
 
Upvote 0
I love this concise solution but I'm not sure I understand it:

With data in A1 try

=TRIM(LEFT(RIGHT(" "&SUBSTITUTE(TRIM(A1)," ",REPT(" ",60)),120),60))

Can someone tell me how this would look to extract the third to last word?

Thanks in advance!
 
Upvote 0
The 120 in the formula is 60x2 (the 2nd to the last word), so change it to 180 (3rd to the last word)
=TRIM(LEFT(RIGHT(" "&SUBSTITUTE(TRIM(A1)," ",REPT(" ",60)),180),60))
 
Upvote 0

Forum statistics

Threads
1,224,829
Messages
6,181,219
Members
453,024
Latest member
Wingit77

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