If you have a date in col1, a name in col2 of sheet1, can you use a vlookup to search for the name in sheet2 and return the only first date greater if that name in sheet2 has multiple dates?
You can nest your vlookup inside an if(countif to make it lookup only if your condition is met. Whatever you are looking up needs to be in a column to the left of the date. You will also need to have your list of dates sorted descending.
Here is the formula in the example below: IF(COUNTIF($A$2:$A$6,D2)>1,VLOOKUP(D2,$A$2:$B$6,2,0),"")
Formula explanation:
Count the number of time the value of D2 appears in A2:A6. If it appears more than 1 time, return the value of adjacent cell to the right, otherwise, return blank.
REVISION
A basic vlookup with an approximate match will work for this. When the match type is set to approximate, it returns the next higher result.
=VLOOKUP(A1,E1:F6,2,1)
REVISION #2
In order to omit values that are equal to or lesser than the value in column B, you'll need to use an index/match array. Enter the formula below and then while your cursor is in the cell, press control+shift+enter. Excel will then add curly braces around the formula and calculate it as an array and return the answer.
=IFNA(INDEX($F$1:$F$6,MATCH(1, ($E$1:$E$6=A1)*($F$1:$F$6>B1),0)),"")
Without the IFNA wrapped around the Index/Match formula, if there are no matches with a greater date, Excel will return a #N/A error. However, it will also return a #N/A error if you don't get the control+shift+enter done correctly.
I recommend you first enter the formula below, which doesn't include the IFNA wrapper, and confirm that some matches are returned. If your item doesn't have any matches, then #N/A will be returned, but you'll know the formula is working properly. Then change the formula to the one above that does include the IFNA wrapper, so that blanks are returned in place of #N/A.
=INDEX($F$1:$F$6,MATCH(1, ($E$1:$E$6=A5)*($F$1:$F$6>B5),0))
After the first is done, you can double-click the lower-right corner of the cell to populate the rest of the column.
Related
I want to use the match function in Excel the following way: match(True, D2:J2>=K1,0), to find the smallest value that is greater than or equal to lookup_value. My problem is how to change the row number in the array, since the row number is on his part the result of a match function.
Thanks for the help in advance!
Your baseline formula is:
=MATCH(TRUE,D2:K2>=K1,0)
which looks at row #2:
To change that row, lets put 7 in cell A1 to mean use row #7. We change the formula to:
=MATCH(TRUE,INDEX(D:D,A1):INDEX(K:K,A1)>=K1,0)
So the value in A1 defines the row that MATCH() should use.
EDIT#1:
Here is another example of using INDEX() to return a cell reference.
Say we have data in column A. We want the user to be able to select parts of the column (start and stop rows) and sum the part. However, we don't want the user to tinker with the formula. In fact we are going to lock the formula cell so the user can't destroy the formula. We tell the user to put the start row in D1 and the end row in D2.
We put the formula in cell D3:
=SUM(INDEX(A:A,D1):INDEX(A:A,D2))
Is IF(ISNUMBER(A1:A100),A1:A100,"") an array formula? If not, what is it?
I copied a list of holidays from a web site and pasted it to Excel. The original data had four columns (date, name of the holiday, weekday, note). After pasting to Excel, everything appeared in column A, like this:
date
name of the holiday
weekday
note
date
name of the holiday
.....
.....
I tried several ways to see if the data could be pasted into columns to no avail. So, I needed to extract the dates to another column. In column B, I entered this formula =IF(ISNUMBER(A1:A100),A1:A100,""). It worked to extract the dates from column A to column B.
I am not sure if it is an array formula as, unlike other array formulae, it doesn't need Ctrl-Shift-Enter. Yet, ISNUMBER usually takes a cell as the argument, not an array, and IF usually doesn't return an array.
IF and ISNUMBER are not array functions, but they can be used in array formulas.
Outside of an array formula, they accept only single input values and return single output values.
In an array formula, they can accept an array of inputs values and will return an array of outputs values.
Without pressing CTRL-SHIFT-ENTER, the formula you've specified is not an array function.
What you're seeing is the behaviour when a function that is expecting a single value is given a range and entered without pressing CTRL-SHIFT-ENTER but the input range overlaps with the row where the formula is placed.
Entering a range when a single value is expected will return the value from the range on the same row in which the formula is entered if it overlaps, otherwise it will return an error.
You are getting output only because you are placing the formula next to the rows being referenced; and it is giving the same result as if you had entered the formula normally and then filled down: i.e. putting =IF(ISNUMBER(A1),A1,"") in cell B1 and filling down.
Note that if you entered =IF(ISNUMBER(A1:A100),A1:A100,"") in cell B2 instead of cell B1 and then filled down, then the values still appear in the same row and not shifted down by a row as you might expect. Again, this is because it looks at the value in the same row just because the range overlaps with the current row.
Compare to putting =IF(ISNUMBER(A1),A1,"") in cell B2 and filling down, where you then get the values shifted down by a row as expected.
If you entered the original formula again in cell B101 (below the input range) and filled down, you get no values at all (even if there is data next to the cell) because the input range no longer overlaps the current cell. In fact, if you used the Evaluate Formula tool from the Formulas tab, you'll see that the range A1:A100 returns a #VALUE error immediately.
This behaviour is confusing and should be avoided at all costs. Only enter ranges when a function expects a range, or when an array formula is being intentionally created using CTRL-SHIFT-ENTER.
If after pasting your data to excel sheet looks like below then you can use following formula.
As shown to above screenshot user below formula to C1 cell then drag down and right as needed.
=INDIRECT("A"&(ROW()-1)*4+COLUMNS($A$1:A$1))
This formula will produce 0 (zero) for empty cells. To hide zero (0) use a IF() condition like below.
=IF(INDIRECT("A"&(ROW()-1)*4+COLUMNS($A$1:A$1))=0,"",INDIRECT("A"&(ROW()-1)*4+COLUMNS($A$1:A$1)))
I'm after a way to a cell to check another cell that I'm inputting text into, and for it to see if that text value is the same anywhere else in the column, and if so, it grabs the number value which is in the same column as itself but in the row of the text that checked for.
So if you use picture, you can see I've currently got E7 selected. I'm wanting it to check the "GOLF COURSE" column for any other row that contains the same text it has in it's own row. For this it's "Course1". I'd like it to check through the rest of column B if there are any matches for "Course1" which there is in B3. If it matches I'm wanting it to then use the value that's in same column as it (E) but the same row as the matched text in column B. In this case I would want it to copy the value that is in E3.
If there wasn't a match (as it's a new course lets say) then I need to be able to just click on the cell and input the numbers needed, which I would be able to do anyway but just throwing it in for sake of info.
I've tried all sorts of googling and thinking how I could possibly do it but it's too difficult for my amateur knowledge of Excel.
I believe you are looking for INDEX/MATCH:
=IF(COUNTIF($B:$B,$B7)>1,INDEX(E:E,MATCH($B7,$B:$B,0)),"New")
I added a COUNTIF check to ensure that the same course exists more than once in column B, without it, you would be getting a circular reference formula (which would also happen with the above formula if the same course appears more than once, but you use this formula on the first occurrence of that course, so make sure do not use it the first time you fill out the PAR scores for a particular course).
Merged Cells Messing With INDEX/MATCH
The Formula
Copy the following formula into cell E7:
=IF(AND($B7<>"",$D7="Par"),IF(ISERROR(MATCH($B7,$B$3:$B5,0)),"Par",INDEX(E$3:E5,MATCH($B7,$B$3:$B5,0))),IF(AND($B6<>"",$D7="Strokes"),IF(ISERROR(MATCH($B6,$B$3:$B4,0)),"Strokes",INDEX(E$3:E4,MATCH($B6,$B$3:$B4,0)+1)),""))
Image
How
We are creating the formula in cell E7.
MATCH
Syntax: MATCH(lookup_value,lookup_array,match_type)
We will use MATCH to find the position of COURSE1 in the above
cells of column B.
The 1st argument is lookup_value which will be the cell in the same
row of our row (7) in column B: B7 where we will lock only the
column (we will not be searching in other columns): $B7.
The 2nd argument lookup_array will be a range. The first cell will be
cell B3 whose row and column we'll lock, because we will always
start the search from this cell in every other cell to the left or
below: $B$3. The last cell will be B5 where we will lock only the
column: $B5.
And finally we will use 0 as the parameter of the 3rd argument
match_type to find an exact match.
Now were ready to write our MATCH formula:
=MATCH($B7,$B$3:$B5,0)
Which will return 1 i.e. an exact (0) match of B7 was found
in the 1st cell of range B3:B5.
We don't want 1 (E3), but the value in the cell (5).
INDEX
The INDEX function has 2 syntaxes where we will use the 2nd:
Syntax 2: INDEX(reference,row_num,column_num,area_num)
Since were using a one-column range we can safely omit the arguments row_num and column_num, which leaves us with:
Modified Syntax: INDEX(reference,area_num)
The INDEX function used this way will return the area_num-th value
of reference i.e. in our case if area_num is 1 it will return the
1st value in our column range, if it is 2, then the 2nd, etc.
The 1st argument reference will be the same sized range of our
MATCH range in column E: $E$3:$E5 where we will remove the
column locks because we also want to return results for other
columns: E$3:E5.
The 2nd argument area_num will be our MATCH formula.
Our current formula looks like this:
=INDEX(E$3:E5,MATCH($B7,$B$3:$B5,0))
which will return the value of cell E3: 5.
Final Adjustments: IF, AND and ISERROR
That would have been almost (Error Checking) all if the cells in column B weren't merged. Therefore we have to use IF to determine if the row in which we're writing the formula contains either Par or Strokes and adjust our so far created formula for both conditions:
=IF($D7="Par",INDEX(E$3:E5,MATCH($B7,$B$3:$B5,0))
=IF($D7="Strokes",INDEX(E$3:E4,MATCH($B6,$B$3:$B4,0)+1)
=IF($D7="Par",INDEX(E$3:E5,MATCH($B7,$B$3:$B5,0)),$D7="Strokes",INDEX(E$3:E4,MATCH($B6,$B$3:$B4,0)+1))
and (3rd condition) check in column B if there is a value in the row where we're creating the formula for a row containing Par, or the row above for a row containing Strokes, using AND:
=IF(AND($B7<>"",$D7="Par"),INDEX(E$3:E5,MATCH($B7,$B$3:$B5,0)),IF(AND($B6<>"",$D7="Strokes"),INDEX(E$3:E4,MATCH($B6,$B$3:$B4,0)+1),""))
Finally we have to add some error checking, because if the match was not found the formula will produce and #N/A error:
=IF(AND($B7<>"",$D7="Par"),IF(ISERROR(MATCH($B7,$B$3:$B5,0)),"Par",INDEX(E$3:E5,MATCH($B7,$B$3:$B5,0))),IF(AND($B6<>"",$D7="Strokes"),IF(ISERROR(MATCH($B6,$B$3:$B4,0)),"Strokes",INDEX(E$3:E4,MATCH($B6,$B$3:$B4,0)+1)),""))
Now we are ready to copy the formula to the right and below as far as we need.
I am newbie to excel. I have this following data in excel sheet.
I want to have the value of G11 returned 27, as the value of its corresponding cell in column D, which is D11 matches to E8, and E9, which then correspond to the values of 14 and 27 in column J. Could someone tell me how to return a match value when I have two match situations and I need the maximum one. I am using the following formula.
=IF(D11=1,0,INDEX($H$4:$H$13,MATCH(D11,$E$4:$E$13,0),1))
I know if I use
=IF(D11=1,0,INDEX($H$4:$H$13,MATCH(D11,$E$4:$E$13,0)+1,1))
it returns me with the value 27 or greater of the both values but it will not work if I have three values and I want the maximum.
This will do it confirmed with ctrl+shift+enter:
{=MAX(IF(E4:E13=D11,J4:J13))}
Curly braces should not be entered manually, be sure to confirm with ctrl+shift+enter
This says:
Look for rows where the value in E matches D11
If you find one, return the value in column J
Give the maximum value of the result you find
This will cause errors if there are no matches. You also probably are designing your sheet in a not ideal way.
You can use the formula:
=IF(D11=1,0,MAX(IF(D11=$E$4:$E$13,$H$4:$H$13,0)))
entered as an array formula (i.e. you press Ctrl+Shift+Enter instead of Enter alone) for G11.
MATCH returns the first match, so that's why I'm using another IF instead.
I have an excel sheet.
Under column E, I have 425 cells with data. I want to check if the same data (i.e. text inside the cell) is repeated anywhere else in any of the remaining 424 cells under column E. How do I do this?
For example, in E54 I have
Hello Jack
How would I check this value to see if it was in any other of these cells?
You could use
=SUMPRODUCT(1/COUNTIF(E1:E425,E1:E425))
to count the number of unique cells in E1:425
An answer of 425 means all the values are unique.
An answer of 421 means 4 values are duplicates of other value(s)
Use Conditional Formatting on all the cells that will highlight based on this formula:
COUNTIF(E:E,E1) <> 1
This is based on the column being E, and starting on E1, modify otherwise.
In Excel 2010 it's even easier, just go into Conditional Formatting and choose
Format only unique or duplicate values
If you have to compensate for blank cells, take the formula supplied above by #brettdj and,
Adjust the numerator of your count unique to check for non-blanks.
Add a zero-length string to the COUNTIFS's criteria arguement.
=SUMPRODUCT((E1:E425<>"")/COUNTIF(E1:E425,E1:E425&""))
Checking for non-blank cells in the numerator means that any blank cell will return a zero. Any fraction with a zero in its numerator will be zero no matter what the denominator is. The empty string appended to the criteria portion of the COUNTIF is sufficient to avoid #DIV/0! errors.
More information at Count Unique with SUMPRODUCT() Breakdown.
This formula outputs "unique" or "duplicates" depending if the column values are all unique or not:
{=IF(
SUM(IF(ISBLANK(E1:E425),0,ROW(E1:E425)))
=
SUM(IF(ISBLANK(E1:E425),0,MATCH(E1:E425,E1:E425,0)))
,"unique","duplicates")}
This is an array formula. You don't type the enclosing {} explicitly. Instead you enter the formula without {} and then press cmd-enter (or something else if not a Mac - go look it up!) If you want to split your formula over multiples lines for readability, use cmd-ctrl-return on a Mac.
The formula works by comparing two SUM() results. If they are equal, all the nonblank entries (numeric or text) are unique. If they are not equal there are some duplicates. The formula does not tell you where the duplicates are.
The first sum is what you get by adding up the row numbers of every non-blank entry.
The second sum does a lookup of each nonblank entry using MATCH(). If all entries are unique, MATCH() finds each entry at its own position, and the result is the same as the first sum. But if there are duplicate entries then a later duplicate will match an earlier duplicate and the later duplicate will contribute a different value to the sum, and the sums won't match.
You might have to adjust this formula:
if you want cells containing "" to count as blank, then use LEN(...)=0 for ISBLANK(...). I suppose you could put other tests in there if you wanted, but I have not tried that.
if you want to test an array not starting at row 1, then you should subtract a constant from ROW(...).
if you have a huge column of cells, you might get integer overflow when computing this sum. I don't have a solution to that.
It's a shame that Excel does not have an ISUNIQUE() function!
This may be a simpler solution. Assume column A contains data in question. Sort on that column. Then, starting in B2 (or first non-blank cell, use the following formula:
=IF(A2=A1,1,0).
Than sum on that column. When sum = 0, all values are unique.
highlight E and on the home tab select conditional formatting > Highlight Cell Rules > Duplicate Values...
It will then highlight everything that is repeated.