I would like to return the characters after "OR XXXXXXXXXXXX" in the reference cell. Rather than using a RIGHT function, I think there is an way to set up an way with "LEN" functions. Here is what I have found so far-
Cell A2:
=IF(
ISERR(SEARCH("LUR",C2))=FALSE,
RIGHT(B2, 10),
C3)
But this isn't work for Cell A2, A3 or so on. Is there any way I can extract only the characters after "OR" in Column B? Thanks!
You can still use RIGHT(), but you make the second parameter based on the LEN() and Find() function:
=RIGHT(B2, LEN(B2) - FIND("OR", B2, 1)-1)
FIND() returns the starting position of the characters "OR" in B2. Substracting that from the length minus 1 more gets us to the right number of characters for the second parameter.
Related
I have a comma separated value in A2 and same numbers in different cells B1, C1, D1.... I want to match them from comma separated value and find out the count in B2, C2, D2. Please see the image attached you will get the context.
Can we achieve this by formula or macro in excel?
Tried formula:
=LEN(TRIM($A$2))-LEN(SUBSTITUTE(TRIM($A$2),C1,","""))
Also, I have two data sets where I will be using this formula to find out the count of number from comma-separated value and based on count I want the repeated ones to come in a different cell please refer the image for better understanding.
Probably not the best solution but get the job done. Please note it is case-sensitive and please make sure to press Ctrl+Shift+Enter upon finishing this formula.
{=SUM(--(EXACT("!"&TRIM(MID(SUBSTITUTE($A2,",",REPT(" ",100)),(ROW(INDIRECT("1:"&LEN($A2)))-1)*100+1,100)),"!"&B1)))}
You can replace ! in the above formula with a unique symbol that will never appear in the text string to be safer.
The logic is to SUBSTITUTE the comma , with and long string of blanks, then use MID to find each value in the text string and return the result as an array, then use EXACT to match each value in the array with the look up value and return a new array of TRUE and FALSE, then SUM up all TRUE which will give the count of the look up value.
UPDATE #2
As requested by OP, here is one way of solving the second query which is to match the same value with the same occurrence from two text strings separated by comma ,.
The formula in Cell C2 is from the original solution which is used to find the occurrence of a given value in a text string;
The formula for Range C6:K6 is an array formula as shown below. I used a helper row to layout the matching values, and excluding the one that has 0 count for both data set;
{=IFERROR(INDEX($C$1:$K$1,,AGGREGATE(15,7,COLUMN(INDIRECT("1:"&COLUMNS($C$1:$K$1)))/($C$2:$K$2=$C$3:$K$3)/($C$2:$K$2>0),COLUMN()-2))&",","")}
The formula in Cell L8 is concatenating all values from Range C6:K6 and remove the last comma , from the final text string:
=LEFT(CONCATENATE(C6,D6,E6,F6,G6,H6,I6,J6,K6),LEN(CONCATENATE(C6,D6,E6,F6,G6,H6,I6,J6,K6))-1)
The following worked for me, give it a try:
Formula in B2:
=(LEN(","&SUBSTITUTE($A$2,",",",,")&",")-LEN(SUBSTITUTE(","&SUBSTITUTE($A$2,",",",,")&",",","&B$1&",","")))/LEN(","&B$1&",")
Drag right...
A simpler way of doing it is to simply calculate the difference in the length of the string minus the length of the string when replacing the value searched by nothing and dividing by the length of the string searched
The formula would be:
=(LEN($A$1)+1-LEN(SUBSTITUTE($A$1&",",B1&",","")))/LEN(B1&",")
There is a much simpler solution:
=COUNTIF(SPLIT($A$2, ","), B1)
Lets say we have two cells A1 and A2:
A1: A, B, 13
A2: C,B,14
Which are Strings. I want to add the values at the end of each cell-string.
Hence what I do to extract a value of a specific cell:
=VALUE(RIGHT(A1, SEARCH(",",A1))))
Returns 13 as a VALUE (or int).
Now, is there a way to add A1 and A2 in a SUM function? I could not find a way to loop through each A cell in a SUM range and work the VALUE magic on it.
A very bothersome solution would be to add all the values together like so:
=SUM(VALUE(RIGHT(A1, SEARCH(",",A1))),VALUE(RIGHT(A2, SEARCH(",",A2))))
But that does not seem optimal. I tried around with IF but it seems that what I am missing is simply the While/For loop to iterate through a range.
With data in A1 through A10, pick a cell and enter:
=SUMPRODUCT(--(TRIM(MID(SUBSTITUTE(A1:A10,",",CHAR(1),2),FIND(CHAR(1),SUBSTITUTE(A1:A10,",",CHAR(1),2))+1,9999))))
The formula isolates the string after the second comma; converts it into an integer; and then sums the integers.
(just be sure that your SUMPRODUCT() covers only cells with data and not any blank cells)
EDIT#1:
a somewhat shorter formula is:
=SUMPRODUCT(--TRIM(RIGHT(SUBSTITUTE(A1:A10,",",REPT(" ",LEN(A1:A10))),LEN(A1:A10))))
EDIT#2:
The "shorter" formula works by replacing all commas with a great number of spaces, so many spaces in fact, that when we look at the RIGHT() part of the expanded string, all we see are spaces followed by some numbers. TRIM() removes these spaces, leaving us the numbers.
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.
I have a column of survey responses to a question in which the data is an integer 1 through 5 inclusive followed by text (e.g., "5 stars - I love it"). I want to sum the integers in the 1st characters. The dirty way would be to create a new column in which all but the first character is stripped, but I thought I'd be slick and avoid this.
However, my CSE array formula seems to be summing COUNTA(...) instead of summing over the LEFT(...,1) in the cells
{=SUM(NUMBERVALUE(LEFT(AC$62:AC$9999,1)))}
I'm wondering why there's an implicit COUNTA included here and whether CSE formula is not a good way to approach this.
with data in A1 through A5, use:
=SUMPRODUCT(--LEFT(A1:A5,1))
As you see, the formula discards everything after the leading digit.
NOTE:
If you replace blanks with zeros, the formula will work.
EDIT#2:
You can avoid the helper column if you use the array formula:
=SUMPRODUCT(--(LEFT(IF(A1:A6="",0,A1:A6),1)))
Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key.
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}