Index & Match to return text value - excel

Having error in my formula.
How do i get it to display matched text output in column referencing on a column?
F11 to display A1 looking up output produce by formulas in rows above it that is not special character "-".
G11 to display B1 looking up output produce by formulas in rows above it that is not special character "-".
H11 to display B6 looking up output produce by formulas in rows above it that is not special character "-".
As shown in the picture below, formula below is my current input to reference column which produces error.
=INDEX(F5:F10,MATCH(A5:A10,A5:A10,0))

Based on Edit, you could use a formula like
=LOOKUP(2,1/(F5:F10=$A$5:$A$10),F5:F10)
Copy it across!
If there's going to only one entry and others as dash (-) then following can also be used.
=SUBSTITUTE(CONCATENATE(F5,F6,F7,F8,F9,F10),"-","")
Explanation for LOOKUP:
We simply compare values in formula column (F in this case) with values in Column A by using
(F5:F10=$A$5:$A$10) which produces results like TRUE;FALSE;FALSE;FALSE;FALSE
when these results are used to divide 1 then they're coerced to numbers (TRUE=1, FALSE=0) so the resultant array looks like 1,#DIV/0!;#DIV/0!;#DIV/0!;#DIV/0!.
We are looking in TRUE result which will be always equal to 1. So we are using a number larger than 1 i.e. 2 as LOOKUP uses binary search. Any large number can be used.
And then outer LOOKUP simply returns the matched item from passed array.
You can precisely see this by using Formula Evaluate option in the ribbon Formulas >> Formula Auditing >> Evaulate Formula.

Related

Find common text within a range of cells(range containing blanks as well)

This is the problem i am facing in Excel formula
enter image description here
In column F, i want to find the common text across A2 to E2 (containing Blanks)
My Question:
Is there a simple way to get the result without VB?
Any help is appreciated,thanks
I found that google sheets has some really cool functions.
If you put the formula =SPLIT(A1, ",", TRUE,FALSE) in the cell after your row of common text (or probably even in a different sheet - "probably because hadn't tried it, though it should), the next x cells (where x is the number of "," in A1 - because "," is the delimitator) will be the text.
then you can put the code =IF(SUM(ARRAYFORMULA(if(REGEXMATCH($A$1:$D$1,F1),1,0)))=COUNTA($A$1:$D$1),F1,"") into an equal number of cells after that (probably should just put into the max number), and =CONCATENATE(I1:L1) into the last cell.
Ok. So to tweak this for yourself: I found that ARRAYFORMULA lets you put an array in place of a single cell in a function inside. how it exactly works I read its like a for loop. but I can't really vouch for that. but here it lets you have REGEXMATCH (which is a Boolean check on the cell you give it for if it contains the given REGEX) check each cell in the array.
the sum will add them up, and the if will match against the COUNTA to find if the number of cells in the array that contain this string is equal to the number of non-empty cells.
the concatenate at the end adds all the cells (containing the regex function) together, and since the only non-empty cells will be the one with the string, that is what this cell will return (no spaces).
code:
results:
the test data:
If you need in specifically Excel... this won't help.
We can use power query to achieve the desired result.
Unpivot the columns in Power query
Split all the columns by Comma delimiter
Create a custom column to see if the first column records exist in the remaining columns.
Use the functionText.contains.
Sample function: =Text.Contains([column.1],[column.1]&[column.2]&[column.3])
If the above function returns TRUE then get the first column result(This is the expected result) and load the data back to your excel

Extracting strings between specific characters in excel and separating them with a comma

Is there a way to extract multiple strings between specific characters in excel and separating them with a comma.
For example:
I am thankful for every help!
The following requires a version of Excel O365 that supports dynamic arrays and the LET function.
If I understand correctly you are looking for something like this.
This formula will list all the positions of all [ in the string using dynamic array functions.
=LET(x,$B$2,
y, SEQUENCE(LEN(x)),
raw, IF(MID(x,y,1)="[",y,""),
filtered, FILTER(raw,raw<>"",""),
filtered)
LET allows you to set names within a formula using parameter pairs. The first is the name; the second is the value of the name. The last parameter is the value returned. In this case, x is set to cell B2. y is set to the array listing the numbers from 1 to the length of x using the dynamic array function SEQUENCE. raw is a list that shows the value of y if that position is [, otherwise it is blank. filtered uses the FILTER function to remove all of the blank rows. filtered is the last argument of the LET function so that is what is returned. If this formula is entered into cell A4 then A4 will show 1, A5 will show 14 and A6 will show 28.
If you then enter a similar formula in B4 replacing [ with ] then the result is {7,21,35} in cells B4, B5 and B6.
Finally, in cell B2 you can enter =TEXTJOIN(", ",TRUE,MID(A2,A4#+1,B4#-A4#-1)). This will return the result you are looking for.
If you are unfamiliar with dynamic arrays, A4# indicates an entire dynamic array starting in cell A4. In this case, it is the same as A4:A6.
More information on Dynamic Arrays
More information on LET
You can't do it with only formulas in Excel 2007. You need VBA UDF then. With Excel O365 having dynamic formula access, this can be done like:
=TEXTJOIN(", ",TRUE,TRIM(LEFT(FILTERXML("<t><s>"&SUBSTITUTE(SUBSTITUTE(A1,"]",REPT(" ",100)),"[","</s><s> ")&"</s></t>","//s[starts-with(., ' ')]"),100)))
Considering that you are using too old version of excel which lacks dynamic array functions and besides too many other useful functions, You may probably have to do a long workaround here.
First using substitute and len You have to find out number of such square parenthesis in each of the row. Thereafter you have to work out the formula of max of such numbers.
Do it like this
Assuming your text-values in A2 for a max of 4 occurrences enter the following formula in B2
=SUBSTITUTE(TRIM(REPLACE(LEFT(A2,FIND("]",A2&"]")-1),1,FIND("[",A2&"["),"")&" "&REPLACE(LEFT(A2,FIND("#",SUBSTITUTE(A2&REPT("]",2),"]","#",2))-1),1,FIND("#",SUBSTITUTE(A2&REPT("[",2),"[","#",2)),"")&" "&REPLACE(LEFT(A2,FIND("#",SUBSTITUTE(A2&REPT("]",3),"]","#",3))-1),1,FIND("#",SUBSTITUTE(A2&REPT("[",3),"[","#",3)),"")&" "&REPLACE(LEFT(A2,FIND("#",SUBSTITUTE(A2&REPT("]",4),"]","#",4))-1),1,FIND("#",SUBSTITUTE(A2&REPT("[",4),"[","#",4)),"")), " ", ", ")
Let's say this is the text in A2
I have a text [123] and some more [4523] and also [552222] how to extract [22]?
This will create a output of 123,4523,552222,22 in B2
There is no "extraction" in your question, just removal. The formula below replaces the unwanted characters with "", thereby removing them. Please try it.
=SUBSTITUTE(SUBSTITUTE(A2,"[",""),"]","")

Count cells that doesn't end with 1?

=(Countifs(B:B;”*”;F:F;”<>*1”))
Why doesn't this work?
I want to count all the rows in the sheet, except the ones that has a number that ends with 1 in column F. It just count all the rows, even the ones in column F that ends with 1.
How do I exclude those?
edit
Some more information!
This is a sample of the data:
Could be up to 8000 rows some days. Column B always says "Independent instruction" so I'm using that as a base to count all the rows. Column F contain only numbers, or blank cells (meaning a number will be added later). I still want to count those rows as well (that's blank). It's just the rows that has a number in column F that ends with 1 that I want to exclude!
SUMPRODUCT gives a bit more flexibility for criteria that involve more than straightforward string-matching:
=SUMPRODUCT(--(LEN($B:$B)>0),--(RIGHT($F:$F,1)<>"1"))
The array formula:
{=COUNT(IF((F:F<>"")*(MOD(F:F;10)<>1);F:F))}
will count all non empty cells in the conditions of your question.
Don't forget to press Ctrl+Shift+Enter to place the formula.
Why doesn't this work?
Apart from the fact that you have transcribed it incorrectly (i.e. missing =, and smart quotes ”) the 'F' condition in quotes is a Text value, a formatting issue #BigBen has mentioned in connection with the 'B' values.
You say It just count all the rows so, syntactically corrected, your formula must be working on (a) all 'B's populated (with Text) and (b) all 'F's Numeric. As 1 and "1" are not the same, none of your entries in ColumnF will be excluded by your attempt (none end in "1", though presumably some do end in 1).
#Pspl's A works because its condition (for the 'F's) is based on MOD (applies to Number format values) and #jsheeran's A (my preference) because RIGHT is a string function that returns Text format even from a Number format value.
Put another way, with say 1 in F1, =F1="1" returns FALSE (so =F1<>"1" and =F1<>"*1" return TRUE - that would not suit you) whereas =RIGHT(F1)="1" returns TRUE (or, to suit you, RIGHT(F1)<>"1" returns FALSE).
You can try to use a combination of SUM and IF. Remember to adjust the formula to match your Excel formatting, i.e. replace commas (,) with semicolon (;).
This is an array formula (enter with Ctrl+Shift+Enter)
=SUM(IF(MOD($F$2:$F$25,10)<>1,1,0))
Result (updated with your data set):
When pasting the image into merged cells, the error looks like that:
So you need to make sure the formula is pasted into a single (not merged) cell.
Array formula for values greater than 1000:
=SUM(IF((MOD($F$2:$F$25,10)<>1)*($F$2:$F$25>1000),1,0))
Array formula for values less than 1000:
=SUM(IF((MOD($F$2:$F$25,10)<>1)*($F$2:$F$25<1000),1,0))
Example:

Excel Index to look up multiple values

I have a small data set of 2 columns and several rows (columns A and B)
I want to return each instance of codeblk 3 in a formula that is elsewhere in my sheet, (so a vlookup is out as it only shows the first instance) if it does not appear then a message to say its not there should come up.
I have the formula partially working but i cant see the reason why its not displaying the values.
My formula is as below:
This is an array
{=IF(ISERROR(INDEX($A$55:$B$70,SMALL(IF($B$55:$B$70=3,ROW($B$55:$B$70)),ROW(1:1))-1,1)),"No value's produced",INDEX($A$2:$C$7,SMALL(IF($B$55:$B$70=3,ROW($B$55:$B$70)),ROW(1:1))-1,1))}
The result that shows up is only "No values produced" but it should reflect statement B, C and D in 3 separate cells (when changing ROW(1:1), ROW(2:2) etc)
{=SMALL(IF($B$56:$B$69=4,ROW($B$56:$B$69)),ROW(1:1))} - This produces the result 68 which is the correct row.
Any ideas?
Thanks,
This is an array formula - Validate the formula with Ctrl+Shift+Enter while still in the formula bar
=IFERROR(INDEX($A$55:$B$70,SMALL(IF($B$55:$B$70=3,ROW($B$55:$B$70)-54),ROW(1:1)),1),"No value's produced")
The issue you are facing is that your index starts it's first row on $B$55, you need to offset the row numbers in the array to reflect this. For example, the INDEX contains 16 rows but if you had a match on the first row you are asking for the 55th row from that INDEX(), it just can't fulfil that.
EDIT
The offset was out of sync as your original formula included another -1 outside of the IF(), I also left an additional bracket in play (the formula above has now been edited)
The ROW() function will essentially translate $B$55:$B$70 into ROW(55:70) which will produce the array {55;56;57;58;59;60;61;62;63;64;65;66;67;68;69;70} so the offset is needed to translate those row numbers in to the position they represent in the indexed data of INDEX().
The other IF() statement then produces and array of {FALSE;2;3;4;FALSE etc.
You can see these results by highlighting parts of the formula in the formula bar and hitting F9 to calculate.

Vlookup returns N/A despite of existing match

I have two tables, table1 and table2. I execute VLOOKUP function in order to fill in 3 columns from table2 into table1.
For some reason, the formula doesn't work for the first row, and doesn't find the exact match from table2 even though it exists.
I made sure that both columns (for comparison) have the same format (General) and there is no extra spacing. Same conditions also apply for the rest of the records, and it works there properly.
table1 - you can see the missing matches for the first row.
table2 - you can see the match does exist, but it is not reflected in table1.
Is there any other reason why VLOOKUP can't find a match for a specific record?
Try directly evaluating equality for the two cells that you believe are equal, for instance if A2 is the value you are looking up and Sheet2!A100 is the value you think should match try this in a cell:
=(A2=Sheet2!A100)
If that returns false then you know that there is some formatting issue or error in your vlookup.
Also try Formulas / Evaluate Formula ribbon command to step through your vlookup in case that highlights something wrong.
Okay - Here's a doozy of a use-case. VLOOKUP and INDEX-MATCH were returning #N/A for values that were "apparently" equal. Cleaned my data with =TRIM(CLEAN(SUBSTITUTE(A1,CHAR(160)," "))) and that didn't work.
Then, I compared two cells that looked like they had matching values and they evaluated to FALSE (A1=B1 resulted in FALSE).
Then, as a last resort, I code checked each ASCII value for each character in the two cells and I found that the "-" in one cell was different from the "-" in the other cell. The first cell has the ASCII value 63 and the second cell had the ASCII value 45 for what looked like was the same "-". Turns out that 63 is a "short dash" and 45 is your standard dash or minus symbol.
The way to evaluate the ASCII codes for each character in a string is to combine the CODE function with the MID or RIGHT functions after testing the cells for length using the LEN function.
Examples:
LEN(A1) should equal LEN(B1)
For the first character in each cell:
CODE(A1) Code defaults to the first character on the left
CODE(MID(A1,2,1) yields the ASCII for the second character
CODE(MID(A1,3,1) yields the ASCII for the second character
and so on
If you have a lot of characters you can post an integer sequence next to your CODE-MID function and point the position argument to the related integer and just copy down or across
Or
You can look for the weird non-numeric character and just test that one for both cells.
Have observed scenarios like this where direct comparison fails (e.g. formula =A1=B1 resulted in FALSE) and yet length =LEN(A1)=LEN(B1) and letter by letter ASCI comparison (=CODE(A1,1,1), =CODE(A1,2,1), =CODE(A1,3,1), etc.) shows no difference.
What worked was to adjust the format of the lookup value inside the VLOOKUP.
e.g.
=VLOOKUP(A1, ARRAY, COL_NUM, FALSE) -> =VLOOKUP(TEXT(A1, "000"), ARRAY, COL_NUM, FALSE)
Here's an issue I encountered: my VLOOKUP formula returns the correct value (1) if I type in the value-to-look-up (1.016) directly in the formula, shown in cell F54.
However, if I referenced a value in column A as the value-to-look-up, the formula returned #N/A, as shown in cell F55.
(I was actually trying to VLOOKUP the current row's A value plus 0.015, i.e. VLOOKUP(A54+0.015, $A$3:$B$203, 2, FALSE))
Yet if I use the ROUND function, then the VLOOKUP formula works, as shown in F56.
I recently encountered the same issue and resolved it by changing the vlookup formula to =VLOOKUP([value to lookup], [lookup table], [column to return in the lookup table], False). Setting the last input argument to "false" forces Excel vlookup function to perform an exact match.

Resources