Column parsing in Excel - excel

One of my excel columns like below.
COL A COL B
----------------------------------------
ABCDEFGH ABCDEFGH-#648-2011 EXT.8503
In column C , I wanted value should be -#648-2011 EXT.8503
How can I do this in Excel?
I have tried formula like this :
=LEFT(B242,LEN(LEFT(A242,LEN(A242))))
However, its not working, please suggest?

Looking at your data it seems that B2 has a value with A2 sticked to the left of it. If this is the case then you could use:
=RIGHT(B2,LEN(B2)-LEN(A2))
If this isn't the case and it is just a coincidence, then I agree with #Tim Biegeleisen his answer :)
EDIT:
Might you want to exclude the hyphen then use:
=RIGHT(B2,LEN(B2)-LEN(A2)-1)

Many solutions:
You could replace the first instance of A1- in B1 with a null string:
=SUBSTITUTE(B1,A1&"-","",1)
or start after a certain location:
=MID(B1,LEN(A1)+2,99)
If you really want to include the hyphen in the result in column C, then make the minor changes in the formulas above
=SUBSTITUTE(B1,A1,"",1)
=MID(B1,LEN(A1)+1,99)

Try using this formula:
=MID(B1, FIND("-", B1), LEN(B1) - FIND("-", B1) + 1)
This says to take a substring, starting at the position of the first dash -, for the remainder of the string after that starting point.

Related

Excel IF Function with LEFT Function criteria

I am using GOOGLE SHEETS and I am trying to manipulate received data in the following way:
In column A, I have a number. In column B I have a department. In column C I change the number to concatenate with the first letter of column B's value ONLY IF the number starts with 36. If it doesn't it simply returns the new number as the original number. I had to use the SEARCH function because IF LEFT
is not working here, so the issue is if changes the number wherever it finds a 36, instead of just those numbers starting with 36. Any assistance will be highly appreciated.
This formula is used in column C :
=IFERROR(IF(SEARCH("36",A2),CONCATENATE(A2,LEFT(B2,1)),A2),A2)
Here is the IF LEFT function that I've tried :
=IFERROR(IF(LEFT(A2,2) = "36",CONCATENATE(A2,LEFT(B2,1)),A2),A2)
(If errors occur or the old number doesn't start with 36 the new number should remain the original)
Thanks in advance
Edit: Changed LEFT function to correct ranges, forgot to edit this in initially when asking the question.
Give this a try:
=IF(LEFT(A2,2)="36",A2 & LEFT(B2,1),A2)
This approach does not use IFERROR() or CONCATENATE().It assumes your version of Excel uses the English version of the function names and uses , as the argument separator.
=IF(LEFT(A2,2)="36",CONCATENATE(A2,LEFT(B2,1)),A2)
=A2 & LEFT(B2, LEFT(A2, 2)="36")
This is a 'golfed' answer: made as short as possible (although, I have left the spaces in for readability)
If the first 2 characters of cell A2 are "36", then LEFT(A2, 2)="36" will be True. Otherwise, LEFT(A2, 2)="36" will be False.
Excel will treat True and False as 1 and 0 - so, the LEFT(B2, LEFT(A2, 2)="36") will take either the first character from cell B2, or no characters from cell B2, and add that to the end of the value from cell A2.

match two columns and concatenate them

I have column A and B, i want to concatenate A with B values into c column using formula but need help. The problem is, if column B has more than two colors, then the formula breaks. I'm not quit sure how to fix the formula to support more than 2 colors which will likely happen on my worksheet. Here's the formula:
=IF(AND(A1="---",B1="---"),"---",IF(A1="",CONCATENATE(OFFSET(A1,-1,0)," - ",B1),CONCATENATE(A1," - ",B1)))
Try:
C1: =CONCATENATE(MAX($A$1:A1),"-",B1)
and fill down.
To account for the "---" entries:
C1: =IF(AND(A1="---",B1="---"),"---",CONCATENATE(MAX($A$1:A1),"-",B1))
Edit: Oh, and if the labels in Column A might not be in a nice numerical sequence, or might be text, you can use:
C1: =IF(AND(A1="---",B1="---"),"---",CONCATENATE(LOOKUP(2,1/(LEN($A$1:A1)>0),$A$1:A1),"-",B1))
Try this:
=INDEX(A:A,MATCH(1E+99,$A$1:A1))&"-"&B1

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))

Nested IFs in function not working

Hi, I'm trying to input a function in C2 in order to assign a numerical value to the minutes given in Column B. The criteria for this can be seen in the image above (starting at G1).
I have tried using a formula I copied from a similar situation but is not working:
=IF(B2<=$A$2,5,IF(B2<=$A$3,4,IF(B2<=$A$4,3,IF(B2<=$A$5,2,1))))
Any help would be appreciated, thanks
The suggestion by #Jeeped above will simplify the formulas needed. If you have to keep the 'A' and 'B' cells as they are listed above, you have to extract the number from the 'x min' format and convert the 'x' to a number so it can be compared (I assume a " " exists after the number. Could search for " min" as well).
=VALUE(LEFT(A2,SEARCH(" ",A2)-1))
Using the above, if A2 = '60 min', the formula will produce a '60'.
Now that the cell contents can be treated as numbers, the comparisons can be made. Formula for C2:
=IF(VALUE(LEFT(B2,SEARCH(" ",B2)-1))<=VALUE(LEFT($A$2,SEARCH(" ",$A$2)-1)),5,
IF(VALUE(LEFT(B2,SEARCH(" ",B2)-1))<=VALUE(LEFT($A$3,SEARCH(" ",$A$3)-1)),4,
IF(VALUE(LEFT(B2,SEARCH(" ",B2)-1))<=VALUE(LEFT($A$4,SEARCH(" ",$A$4)-1)),3,
IF(VALUE(LEFT(B2,SEARCH(" ",B2)-1))<=VALUE(LEFT($A$5,SEARCH(" ",$A$5)-1)),2,1))))
This is ugly, but works given the original question.
Try this formula (in this case for C2):
=SUM((B2<=$A$2:$A$5)*1)+1
It is important to use it as array formula. So after typing or inserting this formula to your cell don't just commit with Return but hit Ctrl+Shift+Return. If you did it right, your formula will be surrounded by curly brackets in formula bar:
{=SUM((B2<=$A$2:$A$5)*1)+1}

String Separate in Excel

mozilla-nss-3.11.4-0.7
gdb-10.12-1.5.2
glibc-dcc-atv-1.0.3-10.6
i want to separate it too in the next B C D cell
mozilla-nss 3.11.4 0.7
gdb 10.12 1.5.2
glibc-dcc-atv 1.0.3 10.6
right now i can use left , right and find function to do it but not quite work well
i use
LEFT(B33,FIND(".",B33)-2) =B cell
RIGHT(B33,FIND(".",B33)) =C Cell
RIGHT(D33,FIND("-",D33)-1) = D Cell
answer is not right anyone can Help me correct my function thank you
The key point here which makes the task difficult - we need to use as separators LAST TWO hyphens in the string, and remain all the rest intact. For such cases ARRAY formulas is the best shot. My solution is below:
Name 6 columns starting A1: String | MAX "-" | 2nd MAX "-" | Str1 | Str2 | Str3
Put your values in Column A starting at A2.
B2 (MAX "-"): type the formula =MAX(IFERROR(SEARCH("-",$A2,ROW(INDIRECT("1:"&LEN($A2)))),0)) but press CTRL+SHIFT+ENTER instead of usual ENTER - this will define an ARRAY formula and will result in {} brackets around it (but do NOT type them manually!).
C2 (2nd MAX "-"): type the formula =MAX(IFERROR(SEARCH("-",$A2,ROW(INDIRECT("1:"&LEN($A2)))),0)*IF(IFERROR(SEARCH("-",$A2,ROW(INDIRECT("1:"&LEN($A2)))),0)=MAX(IFERROR(SEARCH("-",$A2,ROW(INDIRECT("1:"&LEN($A2)))),0)),0,1)) and again press CTRL+SHIFT+ENTER.
Thus we'll obtain positions of LAST TWO hyphens in the string. The rest is easy - ordinary LEFT / MID / RIGHT stuff:
D2: =LEFT($A2,$C2-1), ENTER.
E2: =MID($A2,$C2+1,$B2-$C2-1), ENTER.
F2: =RIGHT($A2,LEN($A2)-$B2), ENTER.
Autofill B:F.
If temporary columns B:C are unwanted - you should replace references to them in D:F for B:C contents (i.e. replace $A2 in =LEFT($A2, with A2 actual formula), but this will result in TOO complicated ARRAY formulas, still doing their job - but difficult to understand the next day even for the creator)
As for the above solution - perhaps it might be improved or simplified, but I'm pretty much familiar with such ROW...INDIRECT constructions from times I had to analyze megabytes of statistic data, so for me it's just as easy as create LEFT / RIGHT. Anyway, it seems to work.
For your convenience my sample file is shared: https://www.dropbox.com/s/p49x32t3a0igtby/StringHyphensSeparate.xlsx
Hope that was helpful)
ADDITION - 2 more simplified solutions to find LAST TWO hyphens (the rest of steps is the same as above):
More simple ARRAY formulas:
B2 (MAX "-"): type the formula =MAX(IF(MID($A2,ROW(INDIRECT("1:"&LEN($A2))),1)="-",ROW(INDIRECT("1:"&LEN($A2))),0)) but press CTRL+SHIFT+ENTER instead of usual ENTER - this will define an ARRAY formula and will result in {} brackets around it (but do NOT type them manually!).
C2 (2nd MAX "-"): type the formula =LARGE(IF(MID($A2,ROW(INDIRECT("1:"&LEN($A2))),1)="-",ROW(INDIRECT("1:"&LEN($A2))),0),2) and again press CTRL+SHIFT+ENTER.
Regular formulas using SUBSTITUTE function:
B2 (MAX "-"): type the formula =SEARCH("#",SUBSTITUTE($A2,"-","#",LEN($A2)-LEN(SUBSTITUTE($A2,"-","")))), ENTER.
C2 (2nd MAX "-"): type the formula =SEARCH("#",SUBSTITUTE($A2,"-","#",LEN($A2)-LEN(SUBSTITUTE($A2,"-",""))-1)), ENTER.
The key for SUBSTITUTE solution is that it may replace only certain instances of matches, i.e. only 2nd or 3rd hyphen. The overall number of hyphens is determined again via SUBSTITUTE formula: length of original string MINUS length of string with ALL hyphens replaced to empty strings: LEN($A2)-LEN(SUBSTITUTE($A2,"-","").
One more trick here - while we should remain the original string intact, we still MAY do anything with it for intermediate solutions! Thus, we replace the hyphen with #, and then search for # in temporary string.
All the above solutions are working, choose what you like / understand better. Hope that will also help in understanding array formulas, since for the same task there are 2 different approaches.
I updated the example file to include the last 2 examples + resulting megaformulas without intermediate steps, link is the same and located above. Good luck!
Here is a less than perfect solution:
Do a search & replace to get rid of any dashes that are not delimiters. For example, replace "mozilla-nss" with "mozillanss"
Put your values in Column A starting at A1
In B1, enter =LEFT(A1,FIND("-",A1)-1)
In C1, enter =SUBSTITUTE(A1,B1,"")
In D1, enter =SUBSTITUTE(LEFT(C1,FIND("-",C1,2)),"-","")
In E1, enter =SUBSTITUTE(SUBSTITUTE(C1,D1,""),"-","")
Fill Down the equations for all your values in Column A.
Edit: Added next line:
Replace "mozillanss" with mozilla-nss".
Your answers are in columns B,D, and E.

Resources