Solved

Extract character string from cell in excel

Posted on 2010-11-24
5
677 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

617 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