Solved

Extract character string from cell in excel

Posted on 2010-11-24
5
676 Views
Last Modified: 2012-05-10
I have text strings from each of which I need to extract a specific character string.  The character string I need to extract always has the same number of characters however the original text strings are not all the same length. An example text string is below.  The segment - Serial number: - is always the same.  The string I need to extract is the 5 digits following Serial number:  There is always a ; following the 5 digit serial number which I do not wish to include.

Equipment QD5fj425;   Serial number: 93222;   Firmware: V 4.47 - 11/08 AV;   QD5 Version: V 6.01

Any help is appreciated. Thank you.
0
Comment
Question by:Dave
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 24

Accepted Solution

by:
StephenJR earned 500 total points
ID: 34206835
This works for your example, but does rely on there being colon space after serial number.

=MID(A1,FIND("Serial number",A1)+15,5)
0
 
LVL 2

Expert Comment

by:Atr3ides
ID: 34206887
Considering you have the original text string in A1, and the segment string ("Serial number") in B1, the formula you are looking for in C1 is =LEFT(RIGHT(A1,LEN(A1)-FIND(B1,A1)-LEN(B1)),FIND(";",RIGHT(A1,LEN(A1)-FIND(B1,A1)-LEN(B1)))-1)
A step by step process to reach this would be:
1. Write the string you need to parse in A1, and the string that identifies the segment in B1
A1 = "Equipment QD5fj425;   Serial number: 93222;   Firmware: V 4.47 - 11/08 AV;   QD5 Version: V 6.01"
B1 = "Serial number:" (the idea is to identify this segment position and find yourself at the beginning of the number you need to extract)

2. Identify the position of the segment in D1
D1 = FIND(B1,A1)
3. Trim the original string removing the text from the beginning to the segment position, including the segment. Have that in E4.
E1 = RIGHT(A1,LEN(A1)-D1-LEN(B1)) - returns the right side of the string having a length equal with the total length of the string minus the position at which the segment begins minus the segment length. )
E1 result should be 93222;   Firmware: V 4.47 - 11/08 AV;   QD5 Version: V 6.01
4. In F1, use the previous returned result to find the delimiter and return the left side of the string until delimiter position
F1=LEFT(E1,FIND(";",E1)-1)                 (returns 93222)

To reach the result provided as an answer, if you need the whole formula in a single string, just recurrently replace the computed cells with the formula contained in them until you base your formula only on A1 and B1.
You can also change B1 with the actual value you are looking for to use a single formula and a hardcoded string, but that won't be so easy to maintain.
B1 = LEFT(RIGHT(A1,LEN(A1)-FIND("Serial number:",A1)-LEN("Serial number:")),FIND(";",RIGHT(A1,LEN(A1)-FIND("Serial number:",A1)-LEN("Serial number:")))-1)
0
 
LVL 13

Expert Comment

by:gbanik
ID: 34206988
=LEFT(MID(A1,FIND("Serial number: ",A1)+LEN("Serial number:")+1,LEN(A1)),5)
for a fixed length of 5
or
=LEFT(MID(A1,FIND("Serial number: ",A1)+LEN("Serial number:")+1,LEN(A1)),FIND("|",SUBSTITUTE(A1,";","|",2))-(FIND("Serial number: ",A1)+LEN("Serial number:")+1))
for a variable length
0
 
LVL 45

Expert Comment

by:patrickab
ID: 34207179
dcruickshank,

The User Defined Function (UDF) below is in the attached file.

Usage: =sno(A1)

where A1 is the cell containing the original string.

The UDF will cope with Serial Numbers up to 6 digits in length.

Hope that helps.

Patrick
Function sno(ByVal rng As Range) As Long
Dim str1() As String

str1 = Split(rng, ";", , vbTextCompare)
sno = --Trim(Right(str1(1), 6))

End Function

Open in new window

serial-no-extract-01.xls
0
 

Author Closing Comment

by:Dave
ID: 34207277
Thank you very much! Works perfectly
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
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…

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

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

Join & Ask a Question