Removing characters from sentence of varying length

Jammyjt

New Member
Joined
Jul 20, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am trying to extract specific data from data descriptions with varying lengths. For example:

1632993689851.png


So in better words, I am trying to take the first letter of each piece of data, followed by the hyphen and then all the numbers. The examples have varying length before the hyphen as well as after. Additionally, some examples have a letter at the end of the numbers which needs to be removed.

I have been using the following formula to remove the letter at the end, if there is one:

=IF(ISNUMBER(--RIGHT(A1)),A1,LEFT(A1,LEN(A1)-1))

For the single letter before the hyphen I have tried using the LEFT function but I am uncertain how to mix the two together, maybe it requires a different solution altogether. Any help on this would be greatly appreciated!

Cheers,

Jamie
 

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.
Try this

Excel Formula:
=LET(x,MID(A1,FIND("-",A1)+1,LEN(A1)),LEFT(A1,1)&"-"&MID(x,1,IF(ISNUMBER(--RIGHT(A1,1)),LEN(A1),LEN(x)-1)))
 
Last edited:
Upvote 0
Hey JEC, unfortunately I don't have the version of Excel that has the LET function, still waiting on the update to come but thank you for your prompt response.

FormR, thank you for your response, this is exactly what I'm looking for, works perfectly with the ability to remove the end of the formula to allow the letter to appear too.

Thank you both!

Cheers,

Jamie
 
Upvote 0
Hi Peter,

Thanks for sending this in, this also works great! Really appreciate the help from everyone.

Cheers,

Jamie
 
Upvote 0

Forum statistics

Threads
1,215,008
Messages
6,122,672
Members
449,091
Latest member
peppernaut

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