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

DataRequire
BW1550T-NAV-L084L
BW1550T-NAV-L089L
BW1550T-NAV-R097R
BW1550T-NAV-R102R
BW1550T-NAV-S117S
BW1550T-NAV-S122S
CFPR180-CS
CFPR180-DM
CFPR180
DTW1150-NAV-ZBULK
DTW1150-NAV-12
DTW1150-NAV-14
GFPR100-CS
GFPR100-DM
GFPR105-CS
GFPR105-DM
BW1550T-NAV-R097R
BW1550T-NAV-S117S
DS2166T1-O/N-AXXS
DS2166T1-O/N-BXS
DS2166T1-O/N-CS
DS2166T1-O/N-DM
DT1138T-NAV-R127R
DT1138T-NAV-S087S
DT1138T-NAV-S092S
DT1138T-NAV-S097S
DT1138T-NAV-S102S
DT1138T-NAV-S107S

<colgroup><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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,215,084
Messages
6,123,029
Members
449,092
Latest member
ikke

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