Need excel formula for the below question - excel-formula

Create a formula that returns only the characters that appear after "X" for the given character strings. The same formula must work for the whole column!
Example of how it should look like after you apply your formula:
765892X329 329
752238X44 44

Here’s one that works:
=REPLACE(A1, 1, SEARCH("X", A1), "")
It first finds where the X is in the cell and replaces all the text from the beginning up to where X is with nothing, in other words removing it, leaving you with just the text after X.
Replace both the A1 in the above formula with the cell position you want to apply the formula to.

Related

How to add white spaces in a field of Excel which is equal to length of a longer word

I have a scenario where I want my Microsoft excel field to have the same length of the longest word in the column.
Basically lets say if I have:
ACBBASDBBADSAD
BADFDFDDF
So here I want to have the second word with less characters to have white spaces at its end to match the length of the first word.
=&" " this definitely helps but I am unable to achieve the above scenario
Consider this screenshot:
In column B the length of each cell of column A is established with the formula =len(A1) copied down.
Cell D2 has the range name MaximumLength and the formula =max(B:B).
With that in place, you can create the padded values with this formula in cell G1, copied down:
=A1&REPT("*",MaximumLength-LEN(A1))
If you don't want to use the helper column and helper cell, you can use this array formula instead:
=A2&REPT("*",MAX(LEN(A1:A15))-LEN(A2))
This formula must be confirmed with Ctrl-Shift-Enter. It is advisable to use defined ranges, not whole columns in array formulas, hence the range in LEN(A1:A15). Adjust as desired.
I've used the "*" character so it is visible. Replace it with a space " " in your scenario.
You can add this formula to count maximum characters and use on some cell, because you will need to press a command for it to work, so every cell can't contain this formula, let's say it is on Z1:
=MAX(LEN($A:$A))
Certify to press ctrl+shift+enter on the formula
Then you use this formula on your cells:=REPT(" ";Z1-LEN(A2))&A2
Edit: Sorry, anwsered late, teylyn is more complete.

Extracting the different length strings from the middle of a string

I am trying to extract the DocType (VARG, NOR, RMRN, CHNG, ADCN) from the middle of the below worksheet. As you can see, there is nothing consistent within the different strings. I am trying to extract the doctype embedded within the string and place it in the corresponding doctype cell to the left of the drawing sheet cell. Alas, I cannot determine a formula to do so. Any help would be greatly appreciated!
DocType Drawing Sheet
100188-NOR03046
10190635-VARG003-V-013R1
10190635-VARG003-V-018
1086-CHNG121701
10908077-RMRNR0190
11613002-NOR1-1
11627748-NOR07146
11639519-ADCN30352
116-NOR6458
11664680-NOR75941R1
12292527-NORGEO-5343
12292400-NORWIP09335
12292527-NORGEO-5343
I have used this formula:
=MID(I679,SEARCH("-",I679)+1,IF(ISERROR(VALUE(MID(I679,SEARCH("-",I679)+4,1))),4,3))
but for the values listed below I got the following results:
DocType Drawing Sheet Correct Result Should Be
NORG 12292527-NORGEO-5343 NOR
NORW 12292400-NORWIP09335 NOR
VARG 10190635-VARG003-V-013R1 VAR
VARG 12292-VARG003-V-016 VAR
R-AD 12295729-R-ADCN167238 ADCN
31-A 12359705-31-ADCN71449 ADCN
R2-A RM12293172-R2-ADCN183214 ADCN
129 RM-12976612-RM2-ADCN183868 ADCN
19- B5-19-1676-NORFSV00098R1 NOR
NORW 12517164-NORWIP10095 NOR
If you need anymore examples just let me know.
I also tried the following formula but it just produced the 0 (zero):
=IF(I9="*VAR*","VAR",IF(I9="*ADCN*","ADCN",IF(I9="*CHNG*","CHNG",IF(I9="*DEVN*",‌​"DEVN",IF(I9="*EER*","EER",IF(I9="*NOR*","NOR",IF(I9="*PPEP*","PPEP",IF(I9="*RMRN‌*​","RMRN",IF(I9="*SCN*","SCN",IF(I9="*WAIV*","WAIV",0))))))))))
A solution for the case where the required substring is preceded by the first hyphen in the string and followed by the next hyphen or digit:-
=LEFT(RIGHT(B2,LEN(B2)-FIND("-",B2)),
MIN(IF(ISNUMBER(FIND({0,1,2,3,4,5,6,7,8,9,"-"},RIGHT(B2,LEN(B2)-FIND("-",B2)))),
FIND({0,1,2,3,4,5,6,7,8,9,"-"},RIGHT(B2,LEN(B2)-FIND("-",B2)))))-1)
If you have a list of the possible document types you can search for them like this:-
=IFERROR(
INDEX({"ADCN","CHNG","DEVN","EER","NOR","PPEP","RMRN","SCN","VAR","WAIV"},
MATCH("ZZZ",IF(ISNUMBER(FIND( {"ADCN","CHNG","DEVN","EER","NOR","PPEP","RMRN","SCN","VAR","WAIV"},B2)),
{"ADCN","CHNG","DEVN","EER","NOR","PPEP","RMRN","SCN","VAR","WAIV"}))),
"")
"...there is nothing consistent within the different strings" - incorrect. From what I can see, the first 3-4 characters after the first "-" contain the data type. 3 Characters if the 4th character is a number. Use whatever data uniformity exists to create your tests that align your data as needed.
This could work like so [assuming your data starts in B2, this formula goes in C2, and gets dragged down]:
=SEARCH("-",B2)
This gives you the character placement of the first "-" in the cell. Then put this in D2 and drag down:
=ISERROR(VALUE(MID(B2,C2+4,1)))
This attempts to convert the character 4 spaces after the "-" into a value. If it's a letter, it will create an error, which results in TRUE. Otherwise it will show FALSE.
Then put this in E2 and drag down:
=MID(B2,C2+1,IF(D2,4,3))
This says - take cell B2, and, starting at the character after the "-", return the text that goes for 3-4 characters. If D2 is TRUE [there was an error in the above formula, meaning the 4th character was not a number], it goes for 4 spaces. Otherwise if D2 is FALSE, it goes for 3 spaces.
This can alternatively all be placed in a single formula in C2 as follows:
=MID(B2,SEARCH("-",B2)+1,IF(ISERROR(VALUE(MID(B2,SEARCH("-",B2)+4,1))),4,3))

Excel find text value in string

I have a string such as K68272CAA6A1
And need to do that, formula will pass the first character (I mean string will be 68272CAA6A1 in mind) and formula will find the first text character. And cell value will be 7. Because first text character is "C" and it's the 7th character of my string (include "K" character).
And after that I'll split rest of them. But I'm confused about this issue.
If I understand you correctly, you are looking for the position of the 2nd letter in your string. That number is given by the following array-entered formula.
To enter an array formula, hold down ctrl+shift while hitting Enter. If you do this correctly, in the Formula Bar you will see braces {...} around the formula:
=MATCH(FALSE,ISNUMBER(MID(A1,ROW(INDIRECT("2:99")),1)/1),0)+1
The 99 just needs to be some number larger than the length of your longest string.
If I understood you correctly, a formula that implements this functionality (assuming cell A1 = K68272CAA6A1 and B1 = K) would be:
=FIND(RIGHT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(RIGHT(A1,LEN(A1)-FIND(B1,A1)),"1",""),"2",""),"3",""),"4",""),"5",""),"6",""),"7",""),"8",""),"9",""),1),RIGHT(A1,LEN(A1)-FIND(B1,A1)))-1
The long sequence of substitute is there to remove the numbers (I couldn't find a specific formula to remove them).
This gigantic formula for your example would simply give the answer 6.
To get the strings separated as you want all you need to do is =LEFT(A1,D1) supposing the long formula is on D1 and =RIGHT(A1,D1), which in your example would yield respectively K68272 and CAA6A1

finding last character on if condition excel

Can you tell me if I want to find the last character in Excel based on condition
let say last character if it is A then replace it with X, or if it is b then replace it with Z.
I want to do it with formula
If your value is in A1 cell, then try applying the following formula in B1 cell.
Formula
=IF(RIGHT(A1,1)="a", LEFT(A1,LEN(A1)-1) &"x", IF(RIGHT(A1,1)="b",LEFT(A1,LEN(A1)-1) & "z",A1))
If you are looking for last character to be exactly A, then try the following formula.
Formula
=IF(EXACT(RIGHT(A1,1),"A"), LEFT(A1,LEN(A1)-1) &"X", IF(EXACT(RIGHT(A1,1),"B"),LEFT(A1,LEN(A1)-1) & "Z",A1))
You can use this formula. See the example sheet to understand the values.
In Example:
"A2": Original Text
"B2": Result
=IF(RIGHT(A2,1)="A",REPLACE(A2,LEN(A2),1,"X"),IF(RIGHT(A2,1)="B",REPLACE(A2,LEN(A2),1,"Z"),A2))

Excel text formula to extract words separated by semicolons in a field

A field in Excel contains words separated by semicolons, e.g.:
A1 = save;the;national;treasure;for;good
How can I apply Excel text formulas to produce separate words from this field in another fields? E.g.:
A2 should contain a formula to get the first word ("save")
A3 should contain a (different) formula to get the second word ("the")
etc.
However these formulas should hold good even when the value in A1 changes, e.g. if the value of A1 is changed to
A1 = hello;there;how;are;you
Any help in this respect will be highly appreciated.
(The problem is writing a function of my own is not allowed in this case, I have to use original functions like find, search, mid, etc.)
You can create a VBA function to split the fields from this example:
Function ExtractElement(str, n, sepChar)
' Returns the nth element from a string,
' using a specified separator character
Dim x As Variant
x = Split(str, sepChar)
If n > 0 And n - 1 <= UBound(x) Then
ExtractElement = x(n - 1)
Else
ExtractElement = ""
End If
End Function
Then the A2 formula would be: =ExtractElement(A1, 1, ";") and A3 would be: =ExtractElement(A1, 2, ";") and so on
If you have your text to parse in A1 then the following formulas should work
In A2 enter the formula
=IF(ISERROR(LEFT(A1,FIND(";",A1)-1)),A1,LEFT(A1,FIND(";",A1)-1))
In B2 enter the formula
=IF(ISERROR(RIGHT(A1,LEN(A1)-FIND(";",A1))),"",RIGHT(A1,LEN(A1)-FIND(";",A1)))
You can then copy those down as far as you need. Column A grabs the left most word, and Column B displays the remaining string to be parsed. If it runs out of words to parse the formula will display a blank. Column B can also be hidden.
If you can use intermediate formulae, then this will work:
A1 -- save;the;national;treasure;for;good
B1 -- blank
C1 -- =IFERROR(FIND(";",$A1,1+(B1)),LEN($A1)+1)
copy C1 into D1:H1
C2 -- =MID($A1,B1+1,(C1-B1)-1)
copy C2 into D2:H2
Row 1 will display the position of each semi-colon in A1, because it starts looking in the string one character past the semi-colon found in the previous cell.
eg cell E1 searches for a semi-colon in A1 starting at D1+1 =10.
The iferror statement in C1:H1 traps the error which will occur when the search finds no further semi-colons, and returns the full length of string A1, plus 1 for an imaginary semi-colon at the end.
B1 needs to be blank to create an initial zero.
Cells C2:H2 then use the Mid function to copy the section of the A1 string starting one character after the value in each of B1:G1, with length (C1-B1)-1, (d1-c1)-1 etc (minus one to cut out the semi-colon itself)
You should get: 5, 9,18,27,31,36 in Row 1, and beneath those cells the individual words.
Hope this helps.

Resources