Extract a particular characters from a cell

DQ2013

New Member
Joined
Nov 7, 2013
Messages
31
Hi Can some one please help me on the following. I have the following data , I only require the first letter after the 2nd dash if the letter is L or R or S and if the length of the characters after the second dash is 4

[TABLE="class: grid, width: 239"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]Data[/TD]
[TD]Require[/TD]
[/TR]
[TR]
[TD]BW1550T-NAV-L084[/TD]
[TD]L[/TD]
[/TR]
[TR]
[TD]BW1550T-NAV-L089[/TD]
[TD]L[/TD]
[/TR]
[TR]
[TD]BW1550T-NAV-R097[/TD]
[TD]R[/TD]
[/TR]
[TR]
[TD]BW1550T-NAV-R102[/TD]
[TD]R[/TD]
[/TR]
[TR]
[TD]BW1550T-NAV-S117[/TD]
[TD]S[/TD]
[/TR]
[TR]
[TD]BW1550T-NAV-S122[/TD]
[TD]S[/TD]
[/TR]
[TR]
[TD]CFPR180-CS[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]CFPR180-DM[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]CFPR180[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]DTW1150-NAV-ZBULK[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]DTW1150-NAV-12[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]DTW1150-NAV-14[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]GFPR100-CS[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]GFPR100-DM[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]GFPR105-CS[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]GFPR105-DM[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]BW1550T-NAV-R097[/TD]
[TD]R[/TD]
[/TR]
[TR]
[TD]BW1550T-NAV-S117[/TD]
[TD]S[/TD]
[/TR]
[TR]
[TD]DS2166T1-O/N-AXXS[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]DS2166T1-O/N-BXS[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]DS2166T1-O/N-CS[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]DS2166T1-O/N-DM[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD]DT1138T-NAV-R127[/TD]
[TD]R[/TD]
[/TR]
[TR]
[TD]DT1138T-NAV-S087[/TD]
[TD]S[/TD]
[/TR]
[TR]
[TD]DT1138T-NAV-S092[/TD]
[TD]S[/TD]
[/TR]
[TR]
[TD]DT1138T-NAV-S097[/TD]
[TD]S[/TD]
[/TR]
[TR]
[TD]DT1138T-NAV-S102[/TD]
[TD]S[/TD]
[/TR]
[TR]
[TD]DT1138T-NAV-S107[/TD]
[TD]S[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try

Excel Workbook
AB
1DataRequire
2BW1550T-NAV-L084L
3BW1550T-NAV-L089L
4BW1550T-NAV-R097R
5BW1550T-NAV-R102R
6BW1550T-NAV-S117S
7BW1550T-NAV-S122S
8CFPR180-CS
9CFPR180-DM
10CFPR180
11DTW1150-NAV-ZBULK
12DTW1150-NAV-12
13DTW1150-NAV-14
14GFPR100-CS
15GFPR100-DM
16GFPR105-CS
17GFPR105-DM
18BW1550T-NAV-R097R
19BW1550T-NAV-S117S
20DS2166T1-O/N-AXXS
21DS2166T1-O/N-BXS
22DS2166T1-O/N-CS
23DS2166T1-O/N-DM
24DT1138T-NAV-R127R
25DT1138T-NAV-S087S
26DT1138T-NAV-S092S
27DT1138T-NAV-S097S
28DT1138T-NAV-S102S
29DT1138T-NAV-S107S
Get Letter
 
Upvote 0
Hi,

Another way :

=IFERROR(IF(MATCH(TRUE,LEFT(RIGHT(A2,5),2)={"-L","-R","-S"},0)>0,LEFT(RIGHT(A2,4),1),""),"")
 
Upvote 0
Another way :

=IFERROR(IF(MATCH(TRUE,LEFT(RIGHT(A2,5),2)={"-L","-R","-S"},0)>0,LEFT(RIGHT(A2,4),1),""),"")
That wouldn't work for values like
CFPR180-LXCS
X-L-GG
 
Last edited:
Upvote 0
Spreadsheet Formulas
CellFormula
B2=IF(AND(LEN(TRIM(MID(SUBSTITUTE(A2,"-",REPT(" ",50)),100,50)))=4,OR(LEFT(TRIM(MID(SUBSTITUTE(A2,"-",REPT(" ",50)),100,50)),1)={"L","R","S"})),LEFT(TRIM(MID(SUBSTITUTE(A2,"-",REPT(" ",50)),100,50)),1),"")

<tbody>
</tbody>

<tbody>
</tbody>
Peter, your formula does not return the letter for this kind of construction...

X-4-L-GG

I do not see the OP's description disallowing that (plus if you replace the third dash with any other non-alphanumeric character, your formula will return the letter).
 
Upvote 0
Peter, your formula does not return the letter for this kind of construction...

X-4-L-GG

I do not see the OP's description disallowing that (plus if you replace the third dash with any other non-alphanumeric character, your formula will return the letter).
Perhaps you interpreted this differently to me.
.. if the length of the characters after the second dash is 4
Additionally, there was no sample data with 3 dashes. The OP seems happy.
 
Upvote 0
Spreadsheet Formulas
CellFormula
B2=IF(AND(LEN(TRIM(MID(SUBSTITUTE(A2,"-",REPT(" ",50)),100,50)))=4,OR(LEFT(TRIM(MID(SUBSTITUTE(A2,"-",REPT(" ",50)),100,50)),1)={"L","R","S"})),LEFT(TRIM(MID(SUBSTITUTE(A2,"-",REPT(" ",50)),100,50)),1),"")

<tbody>
</tbody>

<tbody>
</tbody>
I believe this slightly shorter formula will also work...

=IF(AND(FIND("-",A2&"-",FIND("-",A2)+1)<LEN(A2)-3,OR(MID(TRIM(A2),LEN(TRIM(A2))-4,2)={"-L","-R","-S"})),LEFT(RIGHT(TRIM(A2),4)),"")
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

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