How to print a value in table after checking 2 conditions - excel

I have a table with time on the left and number of houses on top. i want to print a value for a specific house in a specific time. i am using vlookup to match the house and the value but unable to match it with time. as seen in the screenshot the value should only b printed fron 12:15 to 12:45. formula i am using is =IFERROR(VLOOKUP(I$10,$B$3:$C$3,2,FALSE),""). Can anyone help to point me in the right direction.
workbook is attached for sample.
sample workbook

Try this in I11 then fill right and down.
=IF(AND($H11>=$B$6, $H11<=$C$6, I$10=$B$3), $C$3, TEXT(,))

Can you try using INDEX of your table, once you know which row and column you want?
You can then get the row and column number from within your range by using MATCH, for example:
column number: =MATCH(10,[housesRange],0)
and
row number: =MATCH([time],[timeRange],0)
This can be combined with index:
=INDEX([fullTable],[rowNumber],[columnNumber])

Assuming you're looking for a 2 dimensional search of the table, you should use vlookup and match:
Let's for the answer's sake define the table range as
A1:J10
the column number (house number) cell is:
I1
and the start time cell is:
I2
vlookup, does a search on a column and returns a result from the found row in a defined column
to find the column to return, we can use match, match would return the column number of a value, so in this case:
=MATCH(I1,A1:A10,0)
The last parameter, 0, refers to an exact match.
with a vlookup, we have the 2d search:
=VLOOKUP(I2,MATCH(I1,A1:A10,0), 1)
Since the time is set as range, I defined the last parameter of vlookup as 1, so it will found the closest time to the search parameter
Hope that helps

Related

Nested Xlookup First Non-blank Cells

Name Day 1 Day2 Day 3
John 3 2
John 2 1 4
Using a double Xlookup, when I'm searching for John and Day 2, I cannot get the value 1 and I'm trying Index/Xmatch/xmatch to return me 1 but no luck. Any idea to go about it?
###Updated example picture here###
enter image description here
This is my current formula
=XLOOKUP("John",$A$2:$A$3,XLOOKUP("Day 2",$B$1:$D$1,$B$2:$D$3),,2)
Note that your comments show a different case (wildcard search in names) than your question.
The following formula will result in the first found value of the wildcard search for names starting with the search string in F2 and matching the date in F3:
=LET(range,A1:D3,
c,1-COLUMNS(range),
r,1-ROWS(range),
days,TAKE(range,1,c),
names,TAKE(range,r,1),
data,TAKE(range,r,c),
x,FILTER(data,days=F3),
TAKE(
FILTER(x,
(ISNUMBER(XMATCH(F2&"*",names,2)))*
(x<>"")),
1))
You cannot use XLOOKUP two-way exact match, because it returns the first match and you have duplicated values in column Name.
This solution returns the first non blank value from the input data based on the lookup values. In cell H2 put the following formula:
=LET(colIdx, XMATCH(G3,A1:D1), tb, A2:D5, lkCol, INDEX(tb,, colIdx),
INDEX(TAKE(FILTER(tb, (A2:A5=G2) * (lkCol<>0), "Not Found"),1),colidx)
)
and here is the output:
We use LET for easier reading and composition. First we need to identify the column of our interest. The name colIdx, has the column index. Notice in order to deal with only one data range (tb), I search in all column names including Name. Now we need to identify the corresponding column values. The name lkCol represents that.
Now we have all the elements we need to filter and select the information we are looking for:
FILTER(tb, (A2:A5=G2) * (lkCol<>0), "Not Found")
The output will be the rows from tb for name G2 and filtered for non empty rows from G3 column name. The output has all the columns, now we need to select the column of our interest and only the first non empty value. TAKE extracts only the first row and INDEX the corresponding column.

To return the last value in a row for Date and Person to Action (VBA)

I wish to construct 2 current status columns so as find the last values in each row in Excel:
one for the last Date and the other for the last person who needs to act.
Please see the attached jpg To return the last values in a row for Date and Person to Act
I have tried to use the excel functions, namely, INDEX or LOOKUP but to no avail because of the 3 Remarks columns within the table.
I would appreciate it if you could advise me how to craft a VBA code to the above query.
From LC TAN 2020-02-13
You're on the right track.
you can use LOOKUP to return the last element in an array
BUT you have to ensure your array only has the elements that you want to consider
There is a variation of the INDEX function where you can enter an array for the column (or row) argument and return selected items. You enter the array, or arra constant, in a format like:
N(IF(1,*array or arrayConstant*))
So, a formula that would work for your requirements would be:
L6: =LOOKUP(2,1/LEN(INDEX($B6:$J6,N(IF(1,{2,5,8})))),INDEX($B6:$J6,N(IF(1,{2,5,8}))))
and fill down.
You can use MAX for the date to find the latest date in that row.
You can then use IFERROR and VLOOKUP to find the action with that date. i.e. lookup the date that MAX has returned in the first set of columns, and if that returns an error, look in the second. If the second returns an error, look in the third.
As per your sheet, the formula for L6 would be =MAX(B5:I5)
The formula for M6 would be =IFERROR(VLOOKUP(L5,B5:C5,2,FALSE),IFERROR(VLOOKUP(L5,E5:F5,2,FALSE),VLOOKUP(L5,H5:I5,2,FALSE)))
You can then drag the cells down to populate the date and action for every row. You could achieve the same with VBA if you wanted to, but I would have thought that this is the easiest way to get the the desired result.

Excel VBA/Formula to find a cell that includes search term?

I was not sure how to really create the question...
But the problem I am having is this: I have a list (in rows) that relate to a regulatory document, and after trying to create some sort of for loop or elaborate VLookUp/Index formula, I'm requesting help.
For example:
Now I want to use the rows to find the corresponding section in the document. I've already extracted and formatted the compliance document so it is in excel format.
So what I really need is this: a formula or VBA script that can
1. take the compliance number (for example 1A-1 which exist in Cell A3) and go find a cell (in single column D) that has JUST 1A-1, not 1A-1.1, not 1A-1.1.2, etc. and return it to the adjacent cell to 1A-1, for example.
Many thanks ahead of time... I am so lost!! :/
VLOOKUP vs INDEX/MATCH
You can do the 'lookup' two ways (that I'm aware of):
Using VLOOKUP:
The B3 cell contains your formula
=IF(ISERROR(VLOOKUP(A3,C:D,2,FALSE)),"",VLOOKUP(A3,C:D,2,FALSE))
where 'FALSE' is indicating there has to be an exact match and the data doesn't have to be sorted.
Using INDEX with MATCH:
The F3 cell contains the Index/Match formula
=IF(ISERROR(MATCH(A3,C:C,0)),"",INDEX(D:D,MATCH(A3,C:C,0)))
where '0' is indicating there has to be an exact match and the data doesn't have to be sorted.
INDEX/MATCH preferable!?
The MATCH function finds the position (row number if whole column is used) of the found match. This way (there's another) of using the INDEX function uses exactly this found match to return a cell's value in that position (row) in ANY specified column range (column). So they are the ideal combination.
With the VLOOKUP function you have to additionally specify the column index (range_lookup) of a range which could get complicated when the columns aren't adjacent as in this case. Most importantly, the function doesn't work if the lookup data is to the right of the match data.
VLOOKUP NOT WORKING! INDEX/MATCH STILL WORKING!
try this formula
The formula in cells
B2: =INDEX(E:E,MATCH(A2,F:F,0))
C2: =INDEX(G:G,MATCH(A2,F:F,0))
MATCH(A2,F:F,0) is finding Cell A2 in column F (0 means it will find
exact match) and will return the first row number when it would find that
INDEX(E:E,MATCH(A2,F:F,0)) will return contents of column E where row number is returned by the Match formula

Excel Formula: Return value from array with multiple criteria

Suppose the following series:
I am trying to find the latest non 1 value that precedes the latest 1.
In this case it should return 3 and not 4.
1 being the minimum value I have tried to use MATCH(MIN(range),range,0) and add 1 to get the value I needed, but the minimum function gets stuck on the first occurrence of the minimum.
Try
=INDEX(B1:P1,1,MATCH(1,(OFFSET(B1:P1,,-1)=1)*(B1:P1>1),0))
Where B1:P1 is your data range. Of course it is an array formula (SHIFT+ENTER).
Hope that helps.
I can't see a short and snappy answer to this but here is one suggestion assuming the data starts in column A
=INDEX(2:2,AGGREGATE(15,6,COLUMN(INDEX(2:2,MATCH(1,2:2,0)):INDEX(2:2,MATCH(999,2:2)))/(INDEX(2:2,MATCH(1,2:2,0)):INDEX(2:2,MATCH(999,2:2))>1),1))
If the range didn't start in column A, you would have to subtract the number of the column before the first column of the range from the column number returned by the AGGREGATE to get the correct index value relative to the start of the array e.g. for B2:Z2
=INDEX(B2:Z2,AGGREGATE(15,6,COLUMN(INDEX(B2:Z2,MATCH(1,B2:Z2,0)):INDEX(B2:Z2,MATCH(999,B2:Z2)))/(INDEX(B2:Z2,MATCH(1,B2:Z2,0)):INDEX(B2:Z2,MATCH(999,B2:Z2))>1),1)-COLUMN(A:A))
To be honest it wouldn't be worth using a MATCH to find the last number in the range unless the number of cells in the range was very large, so the formula for B2:Z2 would just be
=INDEX(B2:Z2,AGGREGATE(15,6,COLUMN(INDEX(B2:Z2,MATCH(1,B2:Z2,0)):Z2)/(INDEX(B2:Z2,MATCH(1,B2:Z2,0)):Z2>1),1)-COLUMN(A:A))
Formula starting column A
Formula starting at column B

EXCEL - SUM column if date matches TODAY()

I've tried using SUMIF to obtain my results but it doesn't work properly.
I have a row of dates (XX/XX/XXXX format) and I would like to check this row for the current date.
If the row contains the current date, then I would like to sum the total of that column and row 5-20.
For example - today is 10/13/2016. I would like to search for TODAY() in a certain row (Row 1 for example), and if TODAY() is found, then total this column from row 1 down to row 3.
--A-- --B--
10/13/2016 10/14/16
1 50 10
2 10 4
3 5 6
The result should be 65 only IF the date matches TODAY().
I've also checked on giving the column letter based on the date but with no luck.
Any tips are appeciated! Thank you.
I think you can achieve this with a simple IF and a SUM
i.e. in your example above if you want the result to appear on the bottom row you can just use:
=if(B2=today(), sum(B3:B5), "")
This will display the sum at the bottom of the column for columns where the date = today and a blank in the other columns
You need to use the OFFSET function. You can find the documentation here: https://support.office.com/en-us/article/OFFSET-function-C8DE19AE-DD79-4B9B-A14E-B4D906D11B66
In your particular example the following formula will work:
=SUM(OFFSET(D2, 1, MATCH(B2, $D$2:$F$2, FALSE) - 1, 20))
You can see the formula working below. Assuming you know what the SUM formula is doing, I will explain what the OFFSET formula is doing:
First Parameter: Says start at cell D2
Second Parameter: This is how many row up/down do you want to do. In your case you need start at row below the date so '1' it is.
Third Parameter: This is how many columns to the right do you want to
go. Well the number of columns you want to go is based upon where
your date is. So this uses the match formula to figure out how far
to the right to go.
Fourth Parameter: This is how many row do you want to include. I just picked 20 to include the 20 rows below the selected cell.
You obviously need to modify the parameters a little bit to fit your exact data shape.
So I'll give it a shot:
{=SUM(HLOOKUP(TODAY(),Table_With_Dates_and_Three_Rows_Cell_Reference,{2,3,4}))}
NB: Don't type {} but put the formula inside it and then hit Ctrl+Shift+Enter to create what is called an array formula (it does array calculations element by element then submits the aggregating function value---in this case that is sum).

Resources