Improve company productivity with a Business Account.Sign Up

x
Solved

# Excel formula

Posted on 2016-11-18
Medium Priority
48 Views
Last Modified: 2016-11-18
Hi

I want to split product codes which are different lengths but always have a - in the same place.  I want to create a field which is a short code version and have a formula to do the split rather than sorting and doing text to columns the data. It's always the information before the second -

So the data below is in column B
BSR-G19-BE-L
ZR-17-OL
JWS-27-BR-10

In column C I would like
BSR-G19
ZR-17
JWS-27

Many thanks
0
Question by:RichardAtk
• 3
• 2
6 Comments

LVL 35

Accepted Solution

Rob Henson earned 2000 total points
ID: 41892997
Assuming value in B3, use formula in C3:

=LEFT(SUBSTITUTE(B3,"-","|",2),FIND("|",SUBSTITUTE(B3,"-","|",2),1)-1)

This replaces second occurence of "-" with "|" and then pulls everything to left of "|"

"|" is shift plus key next to z
0

LVL 53

Expert Comment

ID: 41893012
Assumes data in A1

=LEFT(A1,FIND(CHAR(1),SUBSTITUTE(A1,"-",CHAR(1),2))-1)
0

Author Closing Comment

ID: 41893024
Perfect thanks
0

LVL 35

Expert Comment

ID: 41893025
Yep, looking at it don't need the SUBSTITUTE part in the first parameter of the LEFT function.

So just:

=LEFT(B3,FIND("|",SUBSTITUTE(B3,"-","|",2),1)-1)
0

LVL 53

Expert Comment

ID: 41893041
...and you get my formula.
0

LVL 35

Expert Comment

ID: 41893046
Indeed, you do. Author accepted my post while I was writing the comment agreeing with yours.
0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

## Join & Write a Comment Already a member? Login.

This article describes a serious pitfall that can happen when deleting shapes using VBA.
As a person who answers a lot of questions, I often see code that could be simplified, made easier to read, and perhaps most importantly made easier to maintain if the code was modified to use the Select Case statement. This article explains how to…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
###### Suggested Courses
Course of the Month4 days, 11 hours left to enroll

#### 586 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.