How to add space before a letter using a formula - excel-formula

How to add a space using an excel formula after a number or before an alphabet?
e.g 1:30PM --> 1:30 PM

Answered by Jerry Jeremiah
If it is just AM and PM you are interested in adding the space before then
=substitute(substitute(A1,"PM"," PM"),"AM"," AM")
If you need a space after a number (or a time including a colon) and the string could be ANYTHING then this might work: =SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,":",": "),"0","0 "),"1","1 "),"2","2 "),"3","3 "),"4","4 "),"5","5 "),"6","6 "),"7","7 "),"8","8 "),"9","9 ")," :",":")," 0","0")," 1","1")," 2","2")," 3","3")," 4","4")," 5","5")," 6","6")," 7","7")," 8","8")," 9","9")

Related

Trim, Mid, substitute, len for the word following the space after a ~ character

I have various strings with varying length and word placement. The pattern is however, every time a word is found with "~" in front of it, I need to pull the word after the space following it. I've researched quite a bit on mid, left, right, etc functions, but have still not been able to come up with the result I need.
Here are 2 examples of strings:
TRANSACTION FEE: SOLD -1 1/1/2/2 ~IRON_CONDOR MA 100 18 MAR 22 385/390/305/300 CALL/PUT #2.37
TRANSACTION FEE: BOT +1 ~VERTICAL
ANTM 100 (Weeklys) 4 MAR 22 480/485 CALL #.63
For number 1, "MA" should be the result. For number 2, "ANTM" should be the result.
Below are two formulas that seem to get me close to what I'm looking for, but I'm unable to connect the finished result because I just don't understand enough about them. My trials often result in errors haha erg.
=MID(A2,FIND("~",A2)+1,FIND(" ",A2,FIND(" ",A2)+1)-FIND(" ",A2)) '//This doesn't work because it returns "Iron_" for number 1 and "Verti" for number 2
=TRIM(MID(SUBSTITUTE(TRIM($A2)," ",REPT(" ",LEN($A2))), (7-1)*LEN($A2)+1, LEN($A2))) '//This doesn't work because the word needed isn't always the 7th word.
=TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",99)),MAX(1,FIND("~",SUBSTITUTE(A2," ",REPT(" ",99)))-50),99)) '//This returns the word that starts with the "~", but I need the word following it
I'm looking for an efficient formula that will 1st search for the word position that starts with the tilde "~" and then return the word following the space after that.
Anyone familiar with this that could offer a working solution?
In B2, formula copied down :
=TRIM(MID(SUBSTITUTE(MID(A2,FIND("~",A2),99)," ",REPT(" ",99)),99,99))
And,
Your 3rd formula could be modified to this in obtain the target result :
=TRIM(MID(SUBSTITUTE($A2," ",REPT(" ",99)),MAX(1,FIND("~",SUBSTITUTE($A2," ",REPT(" ",99)))+99),99))
Try this:
=LEFT(MID(RIGHT(A1,LEN(A1)-FIND("~",A1)),FIND(" ",RIGHT(A1,LEN(A1)-FIND("~",A1)+1)),LEN(A1)),FIND(" ",MID(RIGHT(A1,LEN(A1)-FIND("~",A1)),FIND(" ",RIGHT(A1,LEN(A1)-FIND("~",A1)+1)),LEN(A1))))

Separate second number from text using Excel formula

I have project number in cell I132. Values are like (just an example what they can be):
654321 - 9000 Workshop
654321 - 2100 Subcontractor
654321 - 3500 Unrealistic
654321 - 6400 Flawless victory
I have only one value in I132 (for example) 654321 - 9000 Workshop. How to separate second number after - (9000) using Excel formula?
I have tried with no success:
=IF(ISERROR(FIND(" ";I132;FIND(" ";I132;1)+1));I132;LEFT(I132;FIND(" ";I132;FIND(" ";I132;1)+1)))
If all your data has this same format as your posted examples (6 digit number followed by space dash space), then use:
=MID(A1,10,4)
EDIT:
If the first number is not always 6 characters long, use:
=MID(A1,FIND(" - ",A1)+3,4)
To make it very generic, we can use the following version:
=LEFT(MID(A1,FIND("-",A1)+2,1000),FIND(" ",MID(A1,FIND("-",A1)+2,1000))-1)
This way it will work even if the first and second numbers have more than 6 and 4 digits. This is basing on the assumption that it will have a dash between the numbers and after the second number is a blank space.
If then format is always the same, with 4 digits numbers, formula should be:
=MID(I132, FIND("-", I132) + 2, 4)
Suppose your data has the same structure across board which is
random number + (space)-(space) + random number + (space) + word
You can use the following formula to find the second number:
=FILTERXML("<t><s>" & SUBSTITUTE(A1," ","</s><s>")&"</s></t>","//s[text()='-']/following-sibling::*[1]")
For the logic behind this formula you may give a read to this article: Extract Words with FILTERXML.
Cheers :)

excel extract word (GB) and number before it

I have stuck I have excel sheet I need to extract GB and numbers from a string.
Galaxy S10+ 8/128GB (Snapdragon 855) should be 128GB have no idea how to do it. cannot find any formulas which will use whilecard , any help?
I am using
=IF((LEN(A3)-LEN(SUBSTITUTE(A3," ","")))<2,A3,LEFT(A3,FIND(" ",A3,FIND(" ",A3)+1)-1))
to extract phone name but stusk with a GB for it
In Excel 2013, which has the FILTERXML function, you can use:
=IFERROR(FILTERXML("<t><s>" &SUBSTITUTE(SUBSTITUTE(A1,"/"," ")," ","</s><s>") & "</s></t>","//s[contains(.,'GB')]"),"")
Using the spaces (and replacing the / with a space), we create an XML where each node is defined by the space separation.
We then use an Xpath to return the node that contains GB
Frist we need to replace the / with a space then find the last space before GB and set that as the beginning of the mid formula:
=IFERROR(MID(LEFT(A2,FIND("GB",A2)+1),FIND("}}}",SUBSTITUTE(SUBSTITUTE(LEFT(A2,FIND("GB",A2)+2),"/"," ")," ","}}}",LEN(SUBSTITUTE(LEFT(A2,FIND("GB",A2)+1),"/"," "))-LEN(SUBSTITUTE(SUBSTITUTE(LEFT(A2,FIND("GB",A2)+1),"/"," ")," ",""))))+1,LEN(A2)),"")
If the string meets the following criteria:
The maximum number of numeric characters before GB is no longer than 4, eg. there will be no string showing 12345GB; and
There will always be either / or " "(space) before the numeric value in front of GB, eg. /128GB or 32GB (with a space in front of 32)
you can use the following formula to find the desired text out of the string.
=IFERROR(RIGHT(SUBSTITUTE(MID(A1,FIND("GB",A1)-5,7)," ","/"),LEN(SUBSTITUTE(MID(A1,FIND("GB",A1)-5,7)," ","/"))-FIND("/",SUBSTITUTE(MID(A1,FIND("GB",A1)-5,7)," ","/"))),"")
The logic is to
use MID to extract 5 characters in front of GB plus "GB" (hence 7 characters in total) from the string,
SUBSTITUTE " " (space) with / within the 7 characters from last step,
FIND the position of / within the 7 characters,
use RIGHT function to extract all characters on the right hand side of /,
use IFERROR to show "" (blank cell) if there is no GB in the string.
The formula could be shorter and easier to be interpreted if you use a helper column to store the text string from Step 1.
Cheers :)

Excel Formula to extract previous word (towards left) from a specific position

I have multiple records as below in an excel file say Col A:
Infogain India (P) Ltd. 3-6 yrs Noida
ROBOSPECIES TECHNOLOGIES PVT LTD 0-2 yrs New Delhi
Red Lemon 0-3 yrs Noida(Sector-7 Noida)
Within the data there is a range of years mentioned e.g. 3-6 yrs in the first list item.
I want to extract the data 3-6, 0-2, 0-3 etc from above 3 list items. I understand a search for " yrs " in all the strings will give me the end position. However, I am unable to determine how to find the starting position of the Number of years.
I require the excel formula which will give me the year range.
I do not want to use any VBA for the solution.
If there are no spaces between numbers then you can use following formula.
=TRIM(RIGHT(SUBSTITUTE(TRIM(LEFT(SUBSTITUTE(A3," yrs",REPT(" ",99)),99))," ",REPT(" ",99)),99))
Try,
=TRIM(RIGHT(REPLACE(A1, FIND(" yrs", A1), LEN(A1), TEXT(,)), 4))
Try the following though pretty sure it can be condensed. I have attempted to handle additional white space potentially being present and also the years being multi digit in length e.g. 12-15. Incorporates a method by Raystafarian to find a last occurence of a character.
=RIGHT(TRIM(LEFT(TRIM(SUBSTITUTE(A1,CHAR(32)," ")),FIND("yrs",TRIM(SUBSTITUTE(A1,CHAR(32)," ")),1)-1)),LEN(TRIM(LEFT(TRIM(SUBSTITUTE(A1,CHAR(32)," ")),FIND("yrs",TRIM(SUBSTITUTE(A1,CHAR(32)," ")),1)-1)))-LOOKUP(9.9999999999E+307,FIND(" ",TRIM(LEFT(TRIM(SUBSTITUTE(A1,CHAR(32)," ")),FIND("yrs",TRIM(SUBSTITUTE(A1,CHAR(32)," ")),1)-1)),ROW($1:$1024))))
Try with below formula
=TRIM(RIGHT(SUBSTITUTE(LEFT(A1,SEARCH("yrs",A1)-1)," ","|",LEN(LEFT(A1,SEARCH("yrs",A1)-1))-LEN(SUBSTITUTE(LEFT(A1,SEARCH("yrs",A1)-1)," ",""))-1),LEN(SUBSTITUTE(LEFT(A1,SEARCH("yrs",A1)-1)," ","|",LEN(LEFT(A1,SEARCH("yrs",A1)-1))-LEN(SUBSTITUTE(LEFT(A1,SEARCH("yrs",A1)-1)," ",""))-1))-SEARCH("|",SUBSTITUTE(LEFT(A1,SEARCH("yrs",A1)-1)," ","|",LEN(LEFT(A1,SEARCH("yrs",A1)-1))-LEN(SUBSTITUTE(LEFT(A1,SEARCH("yrs",A1)-1)," ",""))-1))))

Excel function to cut data between to fixed character strings

I have the following text in an excel cell:
SampleID: S-2016-011451 SubmitterID: EIROSSME Sample Name: T1 BTMs - 6/26/16 10:00 PM Lot Nbr: ProductID:
I need to cut the data so that it reads as:
T1 BTMs 6/26/16 22:00
I can format the date using text($cell,"mm/dd/yy hh:mm") but I can't get the =mid(...) to truncate the data between "Name:" and " - ".
1st: =mid(B2;63;26)
2nd: =mid(B5;1;8)
3rd: =mid(B5;11;18)
4th: =concatenate(B7;B8)
If you want to cut between Name: and -, just use:
=find("Name: ";B2)
=find(" -";B2)
and then:
=mid(B2, find("Name: ";B2)+5;find(" -";B2)-find("Name: ";B2)-5)
I.e.:
Assuming you know what to expect after Sample Name:
=MID(A1,SEARCH("Sample Name:",A1)+13,7)
=MID(A1,SEARCH(A4,A1)+LEN(A4)+3,17)
And now you just have to convert the second cell to the date format you want (which you already know how) and concat them like A4&C4 (if C4 is the date after conversion).
Hope it helps ;)
Use SUBSTITUTE to change, so use SUBSTITUTE(a1,"Sample Name:","£££") and SUBSTITUTE(a1,"PM Lot Nbr:","$$$") together, then you'll get £££ T1 BTM......$$$ then you can find the instances of the £££ and $$$ and mid inbetween then, or RIGHT, then LEFT
This gives you the points to cut from and to. You can use the find of the values that we are also substituting, so find PM Lot Nbr etc.
SUBSTITUTE(SUBSTITUTE(J1,"Sample Name","###"),"PM Lot Nbr","|||")
Something similar to this (not complete, I shall finish and tidy)
=MID(SUBSTITUTE(SUBSTITUTE(J1,"Sample Name","###"),"PM Lot Nbr","|||"),LEN("###") + FIND("###",SUBSTITUTE(SUBSTITUTE(J1,"Sample Name","###"),"PM Lot Nbr","|||")),(FIND("|||",SUBSTITUTE(SUBSTITUTE(J1,"Sample Name","###"),"PM Lot Nbr","|||"))-FIND("###",SUBSTITUTE(SUBSTITUTE(J1,"Sample Name","###"),"PM Lot Nbr","|||"))-LEN("|||")))

Resources