# Extracting Data From A String

Sep 9, 2008

I recently had to convert a text file to an Excel file. The text file had to be converted as delimited data since the fixed width column could not convert correctly.

Now that I have the data converted, I have several rows of data strings.

The data I have looks similar to the examples below:

41 AAITQ08082901PER0041 ABC v1.0 NES ABC P111 - Blue 7706 6547 Yes No 140 5 AAITQ08082901PER0005 ABC v1.0 NEG ABC Z113 - Silver R 9222 2743 Yes No 156123 My question is, how do I extract the numbers that follow the word "No" at the end of each string?

Assuming the data starts in column A, is there a formula that I could type into column B that would allow me to return the value of those specific numbers?

## Extracting Data From A Text String

Sep 8, 2009

I have a few hundred rows of text in the fomat below: 1.23456 xxxxxxxxxxxxxxxxxxxx. The “x’s” represent text which is unique to each row. what the formula I need to extract the number (1.23456) at the start of the string? To complicate things the number may be reported to any number of decimal places, so the formula needs to be able to extract the first block of digits at the start of each row and report it as a number that can be used in calculations.

## Extracting Data Into Cells From String

Sep 21, 2009

I am accessing a ratings system for horse racing and trying to extract the top-rated runners for each race using a database query. The problem is that every runner and rating is in one cell and separated by spaces. I have tried using text to columns but obviously can't use space as a delimiter as the horse names have spaces in them sometimes. The one cell basically contains the following string...

COCONUT MOON 100 CARIBBEAN CORAL 100 HOWARDS TIPPLE 97

A2 = COCONUT MOON
B2 = 100
A3 = CARIBBEAN CORAL
B3 = 100
A4 = HOWARDS TIPPLE
B4 = 97

So that I have each horse and it's rating alongside it in the adjoining cell, I figure I somehow need to use LEN, RIGHT, LEFT or something but can't think how to do this

## Extracting Data Between 2 Characters In A Text String

Dec 14, 2013

I have the data string below:

Career:25: 1-0-2 \$13,765

I would like to extract the 1 between the : and - and as a seperate extraction would like te 2 between the - and the \$ I have tried a few things but end up with the - as the length of the data changes

## Extracting Data From File In Directory And Extracting Filename

Mar 20, 2014

I have a directory folder with an active workbook and another workbook id like to copy data from. The Following macro opens up a file in the same directory, copies some data and pastes it in the active workbook. However with this code I have to specify the filename, 'Data.xlsm' in the example code. I would like it to copy data from the only other workbook in the current directory WITHOUT having to specify the name in the code, so just opening it up no matter what filename it has.

In addition I would like to extract the filename from the workbook im copying data from and paste it into the activewoorkbook in sheet 1 Cell A1. I had a look at getopenfilename function but cant seem to make it work for my purpose.

## Extracting Last Date From String

Apr 21, 2014

I have been trying to extract dates from strings.

The formula I have currently works however I've found that sometimes there are two or more dates in the string (at which point I'd like to extract the last date (appointment date)).

## Extracting 1st 4 Characters From A String?

Feb 17, 2014

i have 8 digit invoice numbers. Each 8 digit number starts with one of three 4 digit ID codes. Depending on the first 4 digits, I want a different "company" to show up.

First seems to work fine.

=IF(E6>"1NCC","North Carolina",IF(E6>"2ALA","Alabama",IF(E6>"3SCC","South Carolina")))

## Extracting The Last Name Of A String Of Text

May 15, 2009

I have a column of names, I need to extract the last word

Simon Greaves
Martin John Mackay
Miss E Hoddle
Bob W Blanchflower
Sarah White
D Gascoigne
H G Gomes

Greaves
Mackay
Hoddle
Blanchflower
White
Gascoigne
Gomes

## Extracting Alphanumeric Value From The String

Jul 20, 2009

I have a rather difficult task to accomplish. What I need is to be able to extract an alphanumeric value from the string. It is a serial number of the equipment and it is always nine alphanumeric characters long. The problem is it can be anywhere in string. Example: “2156545 36 month lease NWL023568 Nancy Clay”. The serial number I need to extract is NWL023568.

## Extracting Numbers A From String

Aug 25, 2009

I would like to extract the digits below in red. The variables are the digits in all of the sections vary from a minimum of one digit to the maximum of three digits.

111.222.333.444

## Extracting Name From A Larger String

Jan 23, 2008

I'm trying to extract a first name and surname from a username :

CN=Joe Bloggs/OU=stneots/OU=EU/O=SAC needs to read Joe Bloggs
CN=Fred Smith/OU=stneots/OU=EU/O=SAC needs to read Fred Smith
CN=Ray Jones/OU=stneots/OU=EU/O=SAC needs to read Ray Jones

The string is always in this format and the name always has a space between. Given a day or so I could probably figure it out, but unfortunately deadlines are breathing down my neck,

## Extracting Filepath From A String

Mar 18, 2008

In A2, using VBA I want to extract the string C:SpreadsheetfolderSubfolderTest i.e. take A1 value and exclude the SpreadsheetA.xls.

## Extracting Certain Numbers From String

Feb 6, 2009

I have not managed to find exactly what I am looking for so far..

I have cells with a mix of numbers and strings and I would like to extract certain numbers only.

I.E.
123a bcd8
acbd 1234e

I would like to only extract the first instance of numbers - so in example 1 - 123 and in example 2 - 1234. I have found various methods of extracting all numbers such as:

Function ExtractNums(r As String) As String
'Creates and returns a reference for a regular expression object
With CreateObject("vbscript.regexp")
'Sets the pattern to be non-digits
.Pattern = "D"
'We want to find all matching non-digits
.Global = True
'Replace all non-digits with an empty string and return this value for the function
ExtractNums = .Replace(r, "")
End With
End Function

## Extracting Text From String Vba

May 11, 2007

I need to extract the text from a string that is always less the last three digits. For example if A1 is abcdefg I always have to take off "efg" and extract the rest of it to the left but the length of the string can vary. I can be dirty and record a macro where I find the length, subtract 3 and then using the LEFT worksheet function can get my result, but when I come to try to convert that to VBA. What is the VBA equivalent of LEFT worksheet function and how would I go about using LEN in conjuntion with subtracting 3 from it?

## Extracting Dates From Text String?

Aug 20, 2014

If I have a cell that contains a sentence and part of a date, for example "delivery due 01/09", I would like a formula that reads that cell, identifies the 01/09 bit and returns 01/09/2014.

The only trouble is that the date would always be variable, so it's more a case of "delivery due #/#"... if that's even possible.

## Extracting Numeric Values From String

Jan 5, 2005

My colleague has a problem where he needs to Extract numbers from alphanumberic strings. Here is the formula he is using:

=MID(B7,MATCH(TRUE,ISNUMBER(1*MID(B7,ROW(\$1:\$297),1)),0),COUNT(1*MID(B7,ROW(\$1:\$297),1)))

It works if alphabetic and numbers are clustered together such as scs987
It works if alphabetic and numbers are not clustered together such as scs987dtg

Problem: It does not work when numbers are not clustered together such as scs987dtg1234

## Extracting A Date From A Text String

Sep 22, 2009

I have a column of data in the following format:

261D 31/12/2008

There is also a single space after the end of the date.

Can someone please show me a formula to extract the date from each cell in the column? This is slightly complicated by the fact that the number of days (“D”) could consist of 1, 2, 3 or 4 characters, and the date could also be of variable length (e.g. 1/1/2008 vs 31/05/2008)

## Extracting Specific String From All Cells?

Oct 25, 2012

How does one extract a specific sting/words from each cell? Especially if [formatted data] varys in characters (not suitable for regular LEFT, MID, RIGHT functions use).

Sample Question.xlsx

## Extracting Word From Text String

Sep 11, 2013

I have random text strings which I need to extract the last part from in Excel.

The text string will be made up of code, but the word I need is always to the right of a prefix />

So for instance in A1 I have 76ruihfo:;.>6">/apple

I would want to extract "apple" from the string above into B1.

## Extracting Integers From A Text String

Sep 28, 2005

is it possilble to extract integers from a text string within a cell?

Eg.
Cell A1 - "ABC 123"
I want to extract the "123" from cell A1.

I have many text strings from which I need to extract the integers from.
The trouble is that each text string does not follow a consistent order, so I
cannot use text functions such as LEFT, MID or RIGHT to extract what i need.

## Extracting Words From Word String

Oct 13, 2013

Let's say i do have words : cow, dog, giraffe, elephant, parrot.

The rest will try to explain in the excel file.

## Extracting Values From An Text String (URL)

Oct 14, 2008

I was given a worksheet that contains a column (A) containing about 5,000 URLs (A1 to ~A5000). Each URL string includes three parameters that I want to capture the values.

For example =

[url]

The prameters are known but the values are random up to 256 characters.

I am trying to pull each of the values into a column for sortability and have been mildly successful using MID and FIND but no joy.

## Extracting Email Address From String

Jun 7, 2009

I have a whole host of email adresses

My issue is that in cell A1 i would have the name of the contact (John Smith)

In cell A2 i would then have the email adrress of the contact though it starts as E-Mail: JohnSmith@hotmail.com

What i would like to do is to extract the e mail address of each contact

Another issue is that there may be some blanks so there may be a name of a contact(A2) and then his email address(A3) then a few blank cells so cells A4 and A5 are empty then another address

## Extracting Text Before And After Numeric String

Jul 31, 2009

I'm trying to extract alphanumeric data before and after a numeric string. The numeric string is in the middle of a URL, which is a varying distance from the start and end.

Here's a sample of my data:

URL Page ID Headline Section quiz.impression-http://www.stuff.co.nz/2677193 2677193

http://www.stuff.co.nz/travel/267779...flying-JetStar 2677794 Why-I-hated-flying-JetStar travel http://www.stuff.co.nz/technology/di...eo-a-smash-hit 1675213 Wedding-dance-video-a-smash-hit technology/digital-living http://www.stuff.co.nz/national/crim...ce-in-Auckland 2678248 Man-shot-by-police-in-Auckland national/crime http://www.stuff.co.nz/sport/rugby/s...it-for-Blackie 3674350 NZRU-set-to-bend-it-for-Blackie sport/rugby/super-14

I start with just column A and generate the other three from that.

I'm using some excellent code from a Mr Excel guru (thanks again Peter) to extract the 8-digit numeric string in column B, I just need C (after) and D (before).

That macro is:
Dim Bits
Dim c As Range
Dim i As Long

For Each c In Range("A4", Range("A" & Rows.Count).End(xlUp))....................

## Extracting Texted Characters From A String

Apr 28, 2006

ive search the forums for this particular need and found somthing close but not what i need. i need to write a formula (not VBA) to extract a string of letters which can very in number out of a string of characters in a particular cell.

ex. cell A1= 00abcdefg00-000-00
cell A2 = abcdefg

i've tried different methods but can seem to come up with anything.

## Extracting Sub-folder From File String

Apr 13, 2007

I've got a host of files within a host of directories, e.g:

c:ContractsJim BobJim Bob Site.xls
c:ContractsJane JonesJane Jones Place.xls
c:ContractsJeremy HillsHills House Lvl 1.xls

I'm working in VBA to try to extract the site name from the file string. Unfortunately there is no other reliable location where I can find an accurate name of the site, so it needs to be taken from the second subdirectory. So I'm using the following code to get the file location:

Sub FilePicker(fileToOpen As String)
ChDrive "C:"
ChDir "C:Contracts"
fileToOpen = Application. GetOpenFilename(FileFilter:="PPM Files (*.xls),_
*.xls", Title:="Select a PPM Scope File", MultiSelect:=False)
End Sub

This returns a string along the lines of "c:ContractsJeremy HillsHills House Lvl 1.xls". From this string, I need to isolate the string "Jeremy Hills".

## Extracting Both Numbers And Text From A String

Jun 21, 2007

I have a woorkbook where I have a cell that has the following apperance:

12345678-ABCDEFG

The numbers can vary in length and as well as the text. What I am trying to do is to split this cell into to columns. Column 1 shows the account number, Column 2 should show the Text and the "-" sign should not be in any of the columns ie it should look something like this

Column1 Column2
12345678 ABCDEFG

I have found a useful function for the first part thanx to Mikerickson
URL:Extract Numerical Data

Function midNumber(inputStr As String) As Double
Dim i As Long
For i = 1 To Len(inputStr)
midNumber = CDbl(Val(Mid(inputStr, i)))
If midNumber <> 0 Then Exit Function
Next i
End Function

But how do i seperate the text and how do Crete a macro that would loop through some 2000 rows and create a column A and B from Column A?

## Extracting String From String?

Apr 1, 2014

I have lengthy title names such as "Giant_SOW_20141203 clean US-OPP134163" which i need to extract the ID number which is US-OPP134163. The ID number is the same every time starting with 'US-OPP' and then 6 numeral digits. I am looking for a formula that will extract this ID number from titles. see the file attached for examples of title names and what my end project should look like in column B.

## Extracting Phone Number Out Of String Of Text?

Apr 30, 2013

Is there a way to extract a phone number out of a string of text. The phone number will always be expressed the same way (eight digits seperated by a space half way through) - 9999 9999. But the text before and after the number is random. Is there a macro to do this on a large scale? The method needs to be applied to hundreds of these strings, each on a new line.

An example of the string of text with the phone number underlined:

Alesdro 0 63PnantCey4281 5919 Aledio daSisaon' Brglry

## Extracting Number From Inconsistent Text String

Jul 4, 2014

I have an excel stock price template, where I need the current price to calculate the mid point if the chart.

This is the text I get from the webquery

Underlying stock: SBIN 2699.00 as on Jul 04, 2014 15:30:36 IST

I need a formula to extract the stock price '2699.00' only from this text.

The problems are sometimes its may change to underlying "stock" to "index", SBIN to RELIANCE or TATASTEEL, and the price some times two digit say 16, some times 6 letters say 150.05, or 8 digits say 15160.00

Formula, the text in B1 and need the price at A100.