formula to get cell address relative to position within a range - excel-formula

I have the following array formula:
= MATCH(B2,DATE(YEAR(A1:AZ1),MONTH(A1:AZ1),1),0)
It returns 7, which is correct, refers the first relative position within the range A1:AZ1
However, I would like to get the relative cell address, i.e. A7
What I need to do is actually this:
A B C
1-Jan-15 1-Feb-15 1-Mar-15
AA AB AC
1-Feb-15 1-Mar-15 1-Apr-15
I need to match the values in these ranges and get something like:
AA AB AC
1-Feb-15 1-Mar-15 1-Apr-15
"B" "C" N/A

Okay this will work. You will need to change the references to your actual data. Pay attention to what is relative and what is absolute in the formula.
In the picture this would be put in J12:
=INDEX($D$2:$T$4,ROW(1:1),MATCH(J$11,$D$1:$T$1,0))
Then it would be copied across and down. The relative references will change to what is needed.

Related

Problem extracting data from a cell populated from a formula

I imported a txt document which creates 7 columns of data. One of the data points in the document is a MAC address, however, due to the format of the txt document (and there is no way around this), the MAC address is split up into 6 columns (B-G), with all other pertinent data (non MAC addresses) existing in column B.
I am trying to write a formula to check a cell in column B, and if it contains "BSSID" then it will combine the text in the corresponding row from columns B-G and enters the new value in column H (so it shows as a normal MAC address). If the cell does not contain "BSSID", then the value of that cell just needs to be moved to the corresponding row in column H.
MY PROBLEM IS given the formula below, if the cell contains "BSSID", the corresponding row in column H will only display the value of the cell in the first column, instead of all the columns.
I have tried taking the code, that combines cells in B-G within the formula, and surrounding it in brackets and quotations, with no luck.
I also tried making this a multiple step solution by only running the formula to combine everything in column H, and then in column I, via a formula.
I tried to move the value returned in column H to column I, but I run into the same issue.
And I have tried swapping the return values, just to make sure, I didn't mix up the true return with the false return.
Original Code I would like to get to work:
=IF(ISNUMBER(SEARCH(“BSSID”,A2)),B2&":"&C2&":"&D2&":"&E2&":"&F2&":"&G2,B2)
This is what the code looked like, when I broke it into 2 parts:
Column H: =B2&":"&C2&":"&D2&":"&E2&":"&F2&":"&G2, B2
Column I: =IF(ISNUMBER(SEARCH(“BSSID”,A2)),H2,B2)
Both codes only return the value in cell B2 if true, instead of what should look like a MAC address.
My expected results would be, in a single formula, if B2 contains the string "BSSID" that H2 would show the content of B2-G2 formatted to look like a MAC address; and if B2 does not contain the string "BSSID" then H2 will show the content of B2.
Actual result is that H2, when the formula returns true, only displays B2 and not B2-G2.
I would approach this problem as follows:
Check the cell for BSSID using an IF statement =IF(SEARCH("BSSID",A2), <true>, <false>)
This statement may result in an error though, if "BSSID" isn't found. Your code looks to be fine, but perhaps herein lies the issue. To be sure, we can insert a catch for the errors using IFERROR =IF(IFERROR(SEARCH("BSSID",A2), FALSE), <true>, <false>)
Then, within the <true> section of the IF statement, I would use TEXTJOIN to combine my cells with a colon inbetween ...TEXTJOIN(":",TRUE,B2:G2)...
EDIT: I notice that you say in one location that you are checking cell A2 for "BSSID" and in another you say you are checking cell B2. Perhaps make sure you aren't checking the wrong cell?
=IF(ISNUMBER(SEARCH(“BSSID”,A2)),B2&":"&C2&":"&D2&":"&E2&":"&F2&":"&G2,B2)
...
My expected results would be, in a single formula, if B2 contains the string "BSSID" that H2 would ...

SUMIF equivalent in array formula

I have a range of value (say H6:H20) containing values "g","y" or "r".
In order to count each status and use that as the source of a donut chart, I made a range of 3 cells calculating =COUNTIF($H$6:$H$20,"Green") etc...
Then I tried to be more elegant and create a single array formula returning the count for each letter, that I could eventually use as the source of my chart, without having intermediry calculation range. But I can't get this working.
Input:
g
r
y
g
g
r
g
g
y
Expected output (with a single array formula):
5
2
2
My try: =COUNTIF({"g","y","r"},$H$6:$H$20) -> error
Other try: =SUMPRODUCT(1*$H$6:$H$20={"g","y","r"}) -> error
(both entered in a 3 cells range with Ctrl+Shift+Enter, of course)
What is the right formula ?
You don't need an array formula, though you do need to store that formula as a Defined Name within Name Manager, e.g.:
Name: Series_Values
Refers to: =COUNTIF(Sheet1!$H$6:$H$20,{"g","y","r"})
Change the sheet name (Sheet1 here) as required.
You can then add a series to a chart with the following syntax for the Series values entry:
='Sheet1'!Series_Values
Again, amend the sheet name as required, though be sure to retain the exclamation mark and apostrophes (the latter are not strictly necessary if the worksheet name contains no spacing, though in any case it is good practice).
Excel will actually amend this to:
=Book1!Series_Values
(where Book1 is the assumed workbook name), though this is not important here.
Regards
That's what FREQUENCY function is for. Select 3 cells and CTRL+SHIFT+ENTER following formula:
=FREQUENCY(MATCH($H$6:$H$20,{"g","y","r"},0),MATCH($H$6:$H$20,{"g","y","r"},0))
Assuming this isn't dynamic, and you have a definite amount of rows, you can use the following. Let's say you're putting this formula in row 20:
=COUNTIF($A$1:$A$9,INDEX({"g","r","y"},ABS(20-(ROW()+1))))
and drag down.
Edit: If you want in the same cell, just combine COUNTIF()?
=COUNTIF($A$1:$A$9,"g")&","&COUNTIF($A$1:$A$9,"r")&","&COUNTIF($A$1:$A$9,"y")
=IF({"g","y","r"}="g",COUNTIF($H$6:$H$20,"g"),IF({"g","y","r"}="y",COUNTIF($H$6:$H$20,"y"),IF({"g","y","r"}="r",COUNTIF($H$6:$H$20,"r"))))
long solution as I don't have time to make a more elegant one. You can see the array object with F9 in the formula bar.

get first non-blank value from a specific column, specified by an index. Excel

This array formula allows me to populate D4 by searching for the first non blank value in Column A (see link - https://exceljet.net/formula/get-first-non-blank-value-in-a-list)
=INDEX(A2:A1000,MATCH(FALSE,ISBLANK(A2:A1000),0))
However, I'd like to refine it such that the column being searched changes depending on the value entered in C4.
For example, if the value in C4 were 1 than I'd get the value 13.86. If the value in C4 were 2 I'd get the value 10. See here -
click for link to example data
I tried adapting the above array formula with an IF function but no success. I'm a total novice so be kind :)
=IF(C4=1,(INDEX(A2:A1000,MATCH(FALSE,ISBLANK(A2:A1000)))),IF(C4=1,(INDEX(B2:B1000,MATCH(FALSE,ISBLANK(B2:B1000)))),0))
In D5 as an array formula (with CSE),
=INDEX(A2:B1000, MATCH(FALSE, ISBLANK(INDEX(A2:B1000, 0, C4)),0), C4)
Okay. It is gonna look daunting but trust me if you look closely it really is a very simple combined with few other formulas
Enter the below formula in D4 or desired cell and press Ctrl+Shift+Enter
=INDEX(INDIRECT(SUBSTITUTE(ADDRESS(1,K4,4),"1","")&1&":"&SUBSTITUTE(ADDRESS(1,K4,4),"1","")&100),MATCH(FALSE,ISBLANK(INDIRECT(SUBSTITUTE(ADDRESS(1,K4,4),"1","")&1&":"&SUBSTITUTE(ADDRESS(1,K4,4),"1","")&100)),0))
Here K4 is my input cell(which is C4 for your case) and I have considered a range of 1:100 unlike yours of 1:1000. So change accordingly.
EXPLANATION
ADDRESS function returns a text of address based on input you give. For input 8 it'll give H1
=INDEX(INDIRECT(SUBSTITUTE("H1","1","")&1&":"&SUBSTITUTE("H1","1","")&100),MATCH(FALSE,ISBLANK(INDIRECT(SUBSTITUTE("H1","1","")&1&":"&SUBSTITUTE("H1","1","")&100)),0))
SUBSTITUTE function then strips down the 1 and gives output only H, which is then used with INDIRECT function to get the range.
=INDEX(INDIRECT("H"&1&":"&"H"&100),MATCH(FALSE,ISBLANK(INDIRECT("H"&1&":"&"H"&100)),0))
=INDEX(INDIRECT("H1:H100"),MATCH(FALSE,ISBLANK(INDIRECT("H1:H100")),0))
Rest is exactly your formula.

match formula when first cell in search range is empty?

is it possible to use an empty cell in a match formula?
I have a value in my cell A3. I want to search this value using 'match' in a matrix A4:A13 (or any other matrix). However, in this case, cell A4 is empty (I cannot help it, it is the way figures are returned from another program).
To be able to search in this matrix I thought I could substitute the value in A3 with {empty}.
substituting works. But then, the Match formula does not work.
The actual formula then would be:
=match("";A4:A13;0)
I cannot change the empty cell in my search range. That one is given. Is there something else I can do to make this work?
edit:
this is the objective of my document:
I have a dashboard sheet on which figures presented.
on this sheet, in column A there are first: account name, brand 1, brand 2, brand 3, brand 4, brand 5 (if applicable,), A.VOGEL, OTHER (result of account total minus the sum of all the brands).
So in this case, cells A3:A10. The figures come from a different sheet. This output is like:
a1 = account name (other cells in this row are empty
a2 = empty, b2 contains a value that cannot be used, c2 shows the brand name (and because in this case, it represents the account total and no brand, c2 is empty) and from D2 : L2, there are values, corresponding to the given value in a1.
a3 = empty, b3 contains a value that cannot be used, c3 has the name of the brand and again, in D3: L3 there are the values.
See my example below:
https://www.dropbox.com/s/jv8wvhtw0aa54dd/output%20sheet%201.png
and the dashboard sheet:
https://www.dropbox.com/s/tgt7omkcytm7xef/DASHBOARD%20sheet%201.png
(and after this account 'nl food-drug' many other account will follow with the same structure).
given this structure, I am trying to create a formula which I can easily paste in every row in the dashboard sheet without being concerned my search matrix will be incorrect.
I thought I was able to do this, but I got stuck.
I would like to have only one formula, which contains everything to have the complete search matrix for both the account total and the individual brands, but which also adjusts and refers to the right account. (so adjusts cell references correctly).
I had 2 different formulas which work: 1 for the account total and 1 for the brands. But I am sure there will be a mistake sometime when I copy paste these rows down the sheet.
My formula always refers to the cell where the account name is in. In the example: A3. To always refer to the right cell I was trying the address, match, indirect formula's together.
one formula which is working now:
=ALS(ISFOUT(INDEX(INDIRECT(ADRES(VERGELIJKEN($A$3;'NIELSEN FD-omzet'!$A:$A;0)+2;4;1;1;"NIELSEN FD-omzet")&":"&ADRES(VERGELIJKEN($A$3;'NIELSEN FD-omzet'!$A:$A;0)+6;12;1;1;);WAAR);VERGELIJKEN($A4;INDIRECT(ADRES(VERGELIJKEN($A$3;'NIELSEN FD-omzet'!$A:$A;0)+2;3;1;1;"NIELSEN FD-OMZET")&":"&ADRES(VERGELIJKEN($A$3;'NIELSEN FD-omzet'!$A:$A;0)+7;3;1;1;));0);VERGELIJKEN(B$2;'NIELSEN FD-omzet'!$D$2:$L$2;0)));"";INDEX(INDIRECT(ADRES(VERGELIJKEN($A$3;'NIELSEN FD-omzet'!$A:$A;0)+2;4;1;1;"NIELSEN FD-omzet")&":"&ADRES(VERGELIJKEN($A$3;'NIELSEN FD-omzet'!$A:$A;0)+6;12;1;1;);WAAR);VERGELIJKEN($A4;INDIRECT(ADRES(VERGELIJKEN($A$3;'NIELSEN FD-omzet'!$A:$A;0)+2;3;1;1;"NIELSEN FD-OMZET")&":"&ADRES(VERGELIJKEN($A$3;'NIELSEN FD-omzet'!$A:$A;0)+7;3;1;1;));0);VERGELIJKEN(B$2;'NIELSEN FD-omzet'!$D$2:$L$2;0)))
nice formula, right? :-)
=MATCH(TRUE,INDEX(ISBLANK(A4:A13),0),0)
Say B1:B4 is the table of values an A1 is the value to find.
This formula:
=IF(A1="",MATCH(TRUE,INDEX(B1:B4="",0),0),MATCH(A1,B1:B5,0))
will work where A1 is empty or not! For example:
and for empty:
EDIT#1
For the Poster's case this would be:
=IF(A3="",MATCH(TRUE,INDEX(A4:A13="",0),0),MATCH(A3,A4:A13,0))
or just:
=MATCH(TRUE,INDEX(A4:A13=A3,0),0)

Formula to find match in two-dimensional range

I need a formula that will look up a value in a 2-dimensional range and return the coordinates or cell address of the matching cell. For example:
R A B C
1 John Matt Pete
2 Sara Bret Chad
3 Lila Maya Cami
I want to search the range A1:C3 for Chad and return C2 or 2,3. How can I accomplish this using Excel formulas? (I'll actually end up applying this to Google Sheets).
Thanks!
Old question, but I thought I'd share a much simpler and elegant answer here that doesn't involve helper columns or complicated formulas, so that more people will get things done easier. Assuming that the table contains unique values and that you use E1 to store your search string Chad and E2 to display the result:
if you want the row and column result of 2,3 in E2:
=SUMPRODUCT((A1:C3=E1)*ROW(A1:C3)) & "," & SUMPRODUCT((A1:C3=E1)*COLUMN(A1:C3))
if you want the R1C1 style cell address string of C2 in E2:
=ADDRESS(SUMPRODUCT((A1:C3=E1)*ROW(A1:C3)),SUMPRODUCT((A1:C3=E1)*COLUMN(A1:C3)))
if you want the found cell's contents of Chad in E2:
=INDIRECT(ADDRESS(SUMPRODUCT((A1:C3=E1)*ROW(A1:C3)),SUMPRODUCT((A1:C3=E1)*COLUMN(A1:C3))))
How things work:
SUMPRODUCT returns in this case the sum of the products between a boolean array of TRUE (searched value found in cell) and FALSE (searched value not found in cell) for every cell in the table and the corresponding row/column (absolute) numbers of those cells in the sheet; thus, the result is essentially the row/column (absolute) number of the cell where the value has been found, since TRUE=1 and FALSE=0 in mathematical terms
ADDRESS returns a cell's address as text (not as reference!)
INDIRECT returns the reference corresponding to a cell's text address
Source and credit goes to: this answer by XOR LX. Could have added the link in a comment, mentioning the duplicate question, but I wanted to expand and explain the answer a little bit, therefore more characters were needed.
Assuming you're using Excel 2007 and above.
You will need a helper column. If your table looks like in your example, in cell D1 write:
=IFERROR(MATCH($E$1,$A1:$C1,0),0)
And drag it down. Then in cell E1 write your search value ("Chad" for instance). Then you have your search result in cell E2 with this formula:
=IF(MAX($D:$D)=0,NA(),MATCH(MAX($D:$D),$D:$D,1)&","&MAX($D:$D))
If you want a simpler solution, it is possible to use only one helper (or not at all, at the cost of a complicated formulae).
Let's say I take your example. I will use the D column to display result :
In D1, I put the name I want to find : Chad
In D2, I put the helper that will return an Index of the value searched (-1 if not found) : =IFERROR(MATCH(D1,SPLIT(TEXTJOIN(";",TRUE,A1:C3),";"),0),-1)
In D3, I put the formulae to get the row,column value (FALSE if not found) : =IF(D2<>-1,ROUNDUP(DIVIDE(D2,COLUMNS(A1:C3))) & "," & IF(MOD(D2,COLUMNS(A1:C3))=0,COLUMNS(A1:C3),MOD(D2,COLUMNS(A1:C3))))
If you really want to use only one formulae, it is possible in D3 to replace all references to D2 by the formulae used in D2.
This formula returns the row and column number of a given value in a two-dimensional array.
=LET(
array, B2:D4,
findvalues, C7,
arrayrows, ROWS(array),
arraycols, COLUMNS(array),
rowindex, SEQUENCE(arrayrows*arraycols,,1,1/arraycols),
colindex, MOD(SEQUENCE(arrayrows*arraycols,,0),arraycols)+1,
flatarray, INDEX(array,rowindex,colindex),
valueflatindex, MATCH(findvalues,flatarray,0),
valuerow, ROUNDUP(valueflatindex/arraycols,0),
valuecol, MOD(valueflatindex-1,arraycols)+1,
absvaluerow, MIN(ROW(array))+valuerow-1,
absvaluecol, MIN(COLUMN(array))+valuecol-1,
CHOOSE({1,2},absvaluerow,absvaluecol)
)
A B C D E
1
2 John Matt Pete
3 Sara Bret Chad
4 Lila Maya Cami
5
6
7 find: Chad
8 formula: 3 4
More precisely, this formula scans a given array row by row and returns the address of the first occurrence of a given value.
If you need the row and column numbers relative to the array's top left cell, then in CHOOSE(...), instead of absvaluerow/absvaluecol, use valuerow/valuecol.
If you want the values to be comma separated and in one cell, instead of CHOOSE(...), use absvaluerow & "," & absvaluecol
If your Excel version does not support the latest functions, such as LET, the formula should still work if you rewrite it so that it does not use the LET variables.
Find Multiple Values
You can also find multiple values in an array using this formula as explained in my answer in this thread.

Resources