extract number from a string of text - Excel - excel

I'm trying to pull a number out of the middle of a string of text in excel.
the string is a mixtire of alpha, numeric and some characters.
Example data string:-
Web Address
/products_list.php?retailer=8&cat=43
/products_list.php?retailer=22&cat=43
/products_list.php?retailer=8&cat=1011
/products_list.php?retailer=81&cat=1023
/products_list.php?retailer=147&cat=1224
/products_list.php?retailer=8&cat=1
/products_list.php?retailer=147&cat=4
/products_list.php?retailer=147&cat=401
What i want to achieve is
I got as far as pulling out all the numbers from the text but really couldn't work out how to just get the numbers in the middle or the ones at the end.
My attempted code to fix the issue was:-
=SUM(MID(0&A3,LARGE(ISNUMBER(--MID(A3,ROW(INDIRECT("1:"&LEN(A3))),1))*ROW(INDIRECT("1:"&LEN(A3))),ROW(INDIRECT("1:"&LEN(A3))))+1,1)*10^ROW(INDIRECT("1:"&LEN(A3)))/10)
SCE for an array formula.
If possible, I would prefer a formula over a macro.
oh in case it makes a difference im using Excel 2010.

Retailer (B2):
=LEFT(RIGHT(A2,LEN(A2)-FIND("=",A2)),FIND("&",RIGHT(A2,LEN(A2)-FIND("=",A2)))-1)
Cat Number (C2):
=RIGHT(A2,LEN(A2)-(FIND("cat=",A2)+3))
drag the formula down and

This looks really ugly (I am no excel expert), but it worked with the list you provided.
Formula for retailer:
=MID(A2,FIND("retailer=",A2)+9,FIND("&",A2)-(FIND("retailer=",A2)+9))
Formula for cat number:
=MID(A2,FIND("cat=",A2)+4,100)

Related

Retreiving specific letters from Text in Microsoft Excel

I have the column as you can see in this image.
The Distributor Address is in the format: "Street Address, Postcode, State".
I need to retrieve only "Postcode" and "State" and combine them.
The new column should be like this ➡"NSW2007","VIC3182"...
How could I retrieve the specific letters and combine them?
You can use FILTERXML if you have the newest version of Excel. See Excel - Extract substring(s) from string using FILTERXML for an excellent overview.
In this case, something like the below should work:
EDIT: overlooked the specific format you wanted
=FILTERXML("<t><s>"&SUBSTITUTE(A1,",","</s><s>")&"</s></t>","//s[3]")&
FILTERXML("<t><s>"&SUBSTITUTE(A1,",","</s><s>")&"</s></t>","//s[2]")
Well, here is a different way:
=RIGHT(A2,3)&","&TRIM(MID(A2,FIND(",",A2,1)+2,LEN(A2)-FIND(",",A2,FIND(",",A2,1)+1)))
This does rely on the state being the last 3 characters and the postcode after the first comma...
There are several ways of solving that. I will show a solution using a few basic functions: RIGHT, MID and LEN.
Assuming your data is on A1:
=RIGHT(A1,3)&MID(A1, LEN(A1)-8, 4)
RIGHT returns the 3 last characters from the cell A1.
MID returns the middle of the cell given a starting position and a length.
LEN gives you the starting position of the zip code, which is always the length of the string - 8 in your table.
Is it essential that your data is well organized as in the image to work well. One alternative is finding the ", " as below.
=RIGHT(A1,3)&MID(A1, FIND(", ",A1)+2,4)

How to substring in Excel between different characters?

first-time poster so please bear with me. I am trying to convince Excel to do a substring and failing miserably. The task is simple enough on the surface of it, extract text that's between a fixed set of chars (+, -, * and /), basically mathematical operators.
My input string looks like this:
A+B+C+D
Now, if my string looks like that, or like A-B-C-D, all is good, I can use this and it works (not my code, found on https://exceljet.net/formula/split-text-with-delimiter and modified to suit my needs:
First text: TRIM(MID(SUBSTITUTE($A2,"+",REPT(" ",LEN($A2))),0*LEN($A2)+1,LEN($A2)))
Second: TRIM(MID(SUBSTITUTE($A2,"+",REPT(" ",LEN($A2))),1*LEN($A2)+1,LEN($A2)))
Third: TRIM(MID(SUBSTITUTE($A2,"+",REPT(" ",LEN($A2))),2*LEN($A2)+1,LEN($A2)))
Forth: TRIM(MID(SUBSTITUTE($A2,"+",REPT(" ",LEN($A2))),3*LEN($A2)+1,LEN($A2)))
And all is good, until I have a string like: A-B+C-D or wahtever combo, basically not all the same char.
I tried using Find and Search in different configurations, but I always come to the same problem:
Using substitute gives me the n'th occurance and that's no good as - may be my second symbol or third
Can't dynamically and accurately calculate the length for MID, as it does Nr. of chars, not "until"
I can't use VB script for security reasons, so I am stuck trying to use Excel formulas.
It HAS to be one formula, as in the end, it's part of a bigger formula that's something like this:
CONCATENATE(IF(ISNUMBER(A),A,VLOOKUP(A)),IF(ISNUMBER(A),A,VLOOKUP(A)),IF(ISNUMBER(A),A,VLOOKUP(A)),IF(ISNUMBER(A),A,VLOOKUP(A)))
So I have the input in a cell and my result has to do all the processing in an adjacent cell.
Thank you in advance, at whit's end over here.
You can try FILTERXML() function.
=TRANSPOSE(FILTERXML("<t><s>"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"+","|"),"-","|"),"*","|"),"/","|"),"|","</s><s>")&"</s></t>","//s"))
If you are not on Excel365 then try below formula.
=FILTERXML("<t><s>"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($A1,"+","|"),"-","|"),"*","|"),"/","|"),"|","</s><s>")&"</s></t>","//s[" & COLUMN(A1) &"]")
To learn FILTERXML() go through this article from #JvdV
For lower versions of Excel following formula would work by copying across as much as needed:
=TRIM(MID(SUBSTITUTE(" "&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($A1,"+"," "),"-"," "),"/"," "),"*"," ")," ",REPT(" ",99)),99*COLUMNS($A1:A1),99))
which is fairly similar to what has been posted on Exceljet site.

Dynamically extract string in excel

I have a column called 'cArticle' in excel, containing data in below format. I have a requirement to extract in another column the code that is in brackets. Ex- Z1A,F5C,etc
cArticle
Molecular Dispersion (Z1A)
Acrona Perse (F5C)
Leco Spers (HLP)
Cullar Dipters (LPP)
I have managed to get it partially working by using the below formula, but it still returns with values with the closing brackets. How can I modify it to get the desired results?
RIGHT(cArticle,4)
Thank you in advance!
If the string always ends with (XXX) and the content in the brackets is always 3 digit. You can also try:
=LEFT(RIGHT(cArticle,4),3)
If your code is always at the farthest right and is only 3 characters long, you can use formula as below
=SUBSTITUTE(RIGHT(cArticle,4),")","")
However if your code is not always at the farthest right and may be more or less than 3 characters than you can use formula below, which will work in all cases even if there is no code present
=IFERROR(MID(cArticle,FIND("(",cArticle)+1,FIND(")",cArticle)-FIND("(",cArticle)-1),"No Code")

Result not correct when using if, left and search in excel

I am trying to extract the text to the right of a character pattern of form -201*-*- in excel (I also tried using Access, but the issue persists).
For example, in the text:
EP-005-FI6-2012-1-124-000000-1
I want to extract the number 124; the following formula works:
=LEFT(RIGHT(C1,SEARCH("-201*-*-",C1)+1),3)
124
However, when i apply the exact same formula to extract169 from the text below:
NAATS-MG-D6-2017-1-169-070000-1
The formula returns a completely different result:
=LEFT(RIGHT(C540495,SEARCH("-201*-*-",C540495)+1),3)
-16
The pattern is the same, but the results is completely differnt.
My dataset is too big to go row by row fixing the issue...
Seems to be a simple problem, but i can't get this working...
Any thoughts?
Thank you
Your RIGHT() is wrong. Use:
=LEFT(MID(C1,SEARCH("-201?-?-",C1)+8,9999),3)

Converting letters to text and back again (Excel 2013)

For a piece of coursework I have to complete a register of student grades. I am trying to calculate their overall grades by converting their grades from each of the four units into numbers (which I have done using the VLOOKUP function), but I need to then convert the result of the average back into a letter. I have used VLOOKUP and also a long nested IF statement to try and accomplish this, but no matter what I can never get a valid result. This is what I have so far (this is just a link to my image as I am unable to post one).
I have converted the Target grade into a number using the formula:
=VLOOKUP(D3,'Grade Values'!A$2:B$11,2,FALSE)
Then added up the total of the different grades from the four units using this formula:
=SUM(VLOOKUP(F3,'Grade Values'!A$1:B$11,2,FALSE)+
VLOOKUP(Dashboard!G3,'Grade Values'!A$1:B$11,2,FALSE)+
VLOOKUP(Dashboard!H3,'Grade Values'!A$1:B$11,2,FALSE)+
VLOOKUP(Dashboard!I3,'Grade Values'!A$1:B$11,2,FALSE))
And then averaged it out with this: =J3/4
The problem I am facing at the moment is that when converting this number back to a letter using the same table as in the second screenshot I get an N/A result when I use this formula: =VLOOKUP(K3,Dashboard!A1:B10,1,FALSE)
I can't seem to figure out what's going wrong with the formula at the end. If anyone can please help me figure this out I will appreciate it a lot. Thank you :)
Edit: I apologise for the irrelevant tags, as far as I was aware formulas in Excel were written in JavaScript.
Personally, I would convert the letter grade to ASCII character using the function:
CODE(A1)
use the ASCII Reference Chart for the integer value of each Upper Case character. Note: A=65, B=66, etc... Perform your calculations, then you can use the function:
CHAR(A2)
to convert the number back into a character.
Example:
A1="A"
A2="B"
A3="C"
B1="=CHAR(AVERAGE(CODE(A1),CODE(A2),CODE(A3)))"
just copy the column A in the sheet dashboard and paste it in column C in the sheet dashboard... so you have
A B C
A* 7 A*
A 7 A
B 6 B
....
the formula you have to use is
=VLOOKUP(K3,Dashboard!$B$1:$C$10,2,FALSE)
remember that this time u need to match a number... not a letter

Resources