How to use vlookup function where lookup table array is dynamic? I find the column where I need to lookup values using MATCH function. Can you please suggest how to put integer value coming from MATCH to lookup array function.
I'm not sure if this is all you're asking, but if you're trying to match the column, you can just include the entire range of the spreadsheet. Or you could use an Index function to resize. Lots of options.
To directly answer your question, here's a dynamic vlookup that will include any possible row (as it extends all the way to the bottom of the spreadsheet), and uses Match, to lookup the column header DONKEY. Not very elegant, but it'll get you started. In this case the formula would return 49.
Here's the formula if you want it: =VLOOKUP("California",$I$5:$XFD$1048576,MATCH("Donkey",i4:$XFD$4,0),0)
UPDATE somehow the above answer has gotten two likes so I will make a bigger effort to enhance this answer by explaining that Index Function would probably be a better approach than Vlookup. The formula would look like this: =INDEX(J5:M7,MATCH("Cobra Kia",I5:I7,0),MATCH("Donkey",J4:M4,0),1)
Also, OP tagged VBA although it doesn't seem like this is needed. However if using VBA and trying to do MATCH, always us Application.Match approach, even though it doesn't auto populate like Application.WorksheetFunction.Match. I wrote about that too in this answer... (still not as good as my SHA256!)
Related
I am trying to find a function that I can use that will eliminate duplicate wording when i join two cells together. I will attach a picture to show you what my ideal return is.
Ideal Return
For the Row 1&2 column, this is the function I used (=textjoin(":",True,A2,B2)) , but i would like to find a function that will return me the Ideal Return instead. I am not looking to use the find and replace feature, as I would like to document each step I made, so a function would be best.
Use UNIQUE() function to remove duplicates. Try-
=TEXTJOIN(":",1,UNIQUE(FLATTEN(A2:B2)))
For dynamic spill results use BYROW() function. Try-
=BYROW(A2:B4,LAMBDA(x,TEXTJOIN(":",1,UNIQUE(FLATTEN(x)))))
To make input range dynamic (instead of fixed rows) can use-
=BYROW(A2:INDEX(B2:B,COUNTA(A2:A)),LAMBDA(x,TEXTJOIN(":",1,UNIQUE(FLATTEN(x)))))
What about this one?
=IF(EQ(A2;B2);A2;TEXTJOIN(":";true;A2;B2))
nothing fancy though, if you want the fancy one, the answer with flatten from Harun24hr is better.
But it is easy in what it does, if the cells are the same, then take the first cell, otherwise, concat the results.
I have a long list of part numbers where I need to be able to lookup and retrieve information on them.
These parts can have several alternative part numbers. I have figured out how to get the data returned if my data table only shows one of the possibly part numbers.
The issue is that I want it to be able to look up the columns to find a matching value.
As in the picture below for example. 5-E26 is the equivalent to E5-25. So if I input 5-E26 in the cell, I want it to continue searching to find the value in B7, and return the data as done A4 and A5.
Is this possible to do with Vlookup? Or is there a smarter method for it?
I struggle to fully understand how your data works but here is a possibility:
So the translated version of the formula I used in G2:
=INDEX($D$1:$D$5,AGGREGATE(15,3,((($A$2:$D$5=F2)/($A$2:$D$5=F2))*ROW($A$2:$A$5)),1))
You could also try (in my case):
=INDEX($D$1:$D$5,SUMPRODUCT(($A$2:$D$5=F2)*ROW($A$2:$D$5)))
I have a question on using OFFSET in Excel.
For instance, I have a table with values varying by years.
Then, I have a table with some values varying by year/months.
!!Click here for the tables!!
I would like to write a formula e.g.
=SUMPRODUCT((E2:E37)*OFFSET(A1,C2:C37,1),E2:E37)
but it returns #VALUE!
In short, I would like to use an array of values in C2:C37 i.e. {1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3} to obtain the array {0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.03,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.04,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,0.05,}, and this array is then used in the SUMPRODUCT function.
Can someone help me solve the #VALUE! issue?
Thanks in advance!
Apparently (I didn't know this) Offset is unusual because it can return a set of range objects when used with an array as the second argument. Most functions can't handle this if you pass it to them. But if you put it through the N function, you get the right answer.
=SUMPRODUCT((E2:E37)*N(OFFSET(A1,C2:C37,1)))
or
=SUMPRODUCT((E2:E37),N(OFFSET(A1,C2:C37,1)))
Note that these appear to give an array of #Value! errors when you run them through Evaluate Formula but these resolve after passing through the N function.
Of course it would be more common to do this the easy way and use Index or Vlookup with a helper column. My first thought when trying to do it in a single Array formula without using Offset was this:-
=SUM(E2:E37*MMULT(N(C2:C37=TRANSPOSE((ROW(A2:A4)-1))),B2:B4))
I would think that the Offset way is easier and more efficient.
But in this particular case where there are only a small number of categories you could use this array formula which is perhaps the simplest approach:-
=SUM(CHOOSE(C2:C37+1,0,B2,B3,B4)*E2:E37)
The above formulae only work for the special case where the 'key' is the same as the row number in the lookup column. The offset method can easily be adapted to incorporate a lookup:-
=SUM((E2:E37)*N(OFFSET(A1,IFERROR(MATCH(C2:C37,A2:A4,0),0),1)))
See this reference
Currently I am trying to set up a dynamic range using this formula structure:
=OFFSET($A$2,,,COUNTA($A:$A)-1)
I then modified the formula to find a keyword in the header row:
=OFFSET($A$2,,MATCH("THIS",$1:$1,0),COUNTA($A:$A)-1)
My issue is the COUNTA statement at this point. I want to type something like COUNTA(COLUMN(MATCH("THIS",$1:$1,0))) but it doesn't appear to be this simple.
Instead my workaround is something to the effect of:
COUNTA(INDIRECT(LEFT(ADDRESS(1,MATCH("THIS",$1:$1,0)),2)&":"&LEFT(ADDRESS(1,MATCH("THIS",$1:$1,0)),2)))-1
The entire formula becomes rather long and cumbersome, and I have a feeling that I might be missing something to simplify it. Is there an easier way to do this that would be similar to simply evaluating to COUNTA(Column(10)) or is my approach the most efficient method?
Try this definition
=OFFSET($A$2,,MATCH("THIS",$1:$1,0)-1,COUNTA(OFFSET($A:$A,,MATCH("THIS",$1:$1,0)-1))-1)
The second OFFSET gets the whole column
I don't use excel often, and I haven't really found a good solution to my problem. (which is probably really simple).
I would like to have a cell with a function in my spreadsheet that shows another cell value value that depends on yet another cell value.
Such as:
The Best Deal heading simply uses the formula
=MAX(D3,D1000)
But under Best Deal I would like to display the Name Test1 rather than the numeric value.
Another thing that would be nice to know, is if there is a way to know the maximum row with data in it. So rather than =MAX(D3,D1000) something like =MAX(D3,Max(RowCount_InD))
Obviously that function wouldn't work as I wrote it, but hopefully this pseudo code gives you an idea of what I mean. The purpose is that if more entries are added, it would be able to handle them.
I know this is possible, but I'm having some trouble. Hopefully I can get some help here.
Thanks!
The easiest way to do this is to use a combination of Index and Match. Match will find the position of the maximum value, and then Index will look in column A and return the data in that same position. So, your formula would be:
=INDEX(A$3:A$1000,MATCH(MAX(D$3:D$1000),D$3:D$1000,0))
Put that formula in F3. No hidden columns required.
Sorry, I missed the part about the expanding range. You can do that by using Count or CountA along with Offset. The new formula would be:
=INDEX(A3:OFFSET(A3,COUNTA(A:A)-1,0),MATCH(MAX(D3:OFFSET(D3,COUNT(D:D)-1,0)),D3:OFFSET(D3,COUNT(D:D)-1,0),0))
More complex, but it is basically the same except that it will expand as you add new values at the end.
There is only one 'simple' way I can think of this, but it requires hidden columns (sorry).
set E1 = A1 and fill down all the way (Basically you are making a copy of column A in column E but you are using a formula so it will always be the same)
Then under 'Best deal' - put this formula:
=VLOOKUP(MAX(D3,D1000),$D:$E,2,FALSE)
Then hide column E so it doesn't look like a mess. This way you do not need any fancy macro's and it will work everywhere because it is a normal formula.
"Another thing that would be nice to know, is if there is a way to know the maximum row with data in it. So rather than =MAX(D3,D1000) something like =MAX(D3,Max(RowCount_InD))"
This is a called a dynamic named range. Create a name for the ratio data, and set up the formula for the name range to be this:
=OFFSET($D$3, 0, 0, COUNTA($D$3:$D$1048576), 1)
More info here: http://www.ozgrid.com/Excel/DynamicRanges.htm
Then, assuming you name this named range ratio_data, your function could be referring to =MAX(ratio_data) in combination with index-match as suggested by #Tim Mayes. The range will expand automatically as you add more data.
=INDEX(A$3:A$1000,MATCH(MAX(ratio_data),ratio_data,0))
Ideally, you can replace the A3:A1000 by a dynamic named range as well.