Using INDIRECT() to set dynamic range with VLOOKUP() - excel

I am trying to use INDIRECT() to set a range for a VLOOKUP() function based on a defined numeric value. When stepping through the VLOOKUP() formula, the INDIRECT() function returns what appears to be an acceptable range for my purposes. However, when running the formula, a "#N/A" error is returned and I'm not sure why.
To give a little more flavor, I'm using LEFT() and ADDRESS() to determine the column heading letter based on a MATCH() of a separate value across the top row. Using a fixed offset, the MATCH() functions return the correct column headers and I supply the constants for the range size. Below is my formula:
=VLOOKUP(J2,INDIRECT("$"&LEFT(ADDRESS(1,MATCH($H2,ZAS_Lookup,0)+8,4),1+(MATCH($H2,ZAS_Lookup,0)+8>26))&"$1:$"&LEFT(ADDRESS(1,MATCH($H2,ZAS_Lookup,0)+9,4),1+(MATCH($H2,ZAS_Lookup,0)+9>26))&"$29"),2,TRUE)
As I mentioned, when stepping through to the last step before final calculation, the formula appears as if it will condense down to the following:
=VLOOKUP(5,$DW$1:$DX$29,2,TRUE)
This is not the case, however, since it returns a #N/A. Any idea why? Do I need to use a different function to set the range dynamically?

I realized that I needed to name the tab on which the table resides. It is not enough to simply set the ranges - I also needed to tell Excel which sheet the table was on.

Related

Is there a way to perform an XLOOKUP on a range of values using VBA in a way that if a new row is added in the middle of the range, the XLOOKUP works?

I am attemping to use a range of values to find another set of related values using the formula:
=XLOOKUP(K25:K32, B:B, C:C)
I have considered having the formulas be calculated entirely within VBA however, the resulting program requires that users are able to remove and add rows as necessary, with the dynamic formula on Column R starting at R25 providing the necessary information.
Entering this through excel works as expected, getting the values for every value from K25 to K32 and their respective counterparts from C:C.
Attempting to enter this formula using VBA, namely:
Range("R25").Formula = "=XLOOKUP(K25:K32, B:B, C:C)"
Results in
=XLOOKUP(#K25:K32, B:B, C:C)
Which only works on the first value in K25.
Is there something I am missing here? Thank you!

I need a formula that finds a cell with a given value, range is two dimensional

So the formula that I need is basically the Find feature from the ribbon, but in an excel formula.
Somewhere on the page is a value. I need to be able to search the page and find out what row and column that value is in.
All of the solutions I've seen work from the assumption that I will be able to already know what row or column it is in and find it, searching a one dimensional Range. But now I've got a 2D Range, and all those formulas are returning #N/A.
I will only know two pieces of data going in.
the cell value will be on the sheet, once and only once
it will be somewhere in the range A1:ZZ3500
Some of these sheets are enormous, and using the find function each time is giving me carpal tunnel.
Use AGGREGATE:
ROW:
=AGGREGATE(15,7,ROW(A1:ZZ3500)/(A1:ZZ3500="value"),1)
COLUMN
=AGGREGATE(15,7,COLUMN(A1:ZZ3500)/(A1:ZZ3500="value"),1)
You could roll your own UDF. In a new VBA module:
Function findValue(searchTerm As String, searchRange As Range) As String
findValue = searchRange.Find(searchTerm).Address
End Function
Which can be used in a worksheet formula like =findValue("yourvalue", A1:ZZ3500)
That will spit out the cell reference like $B$2 which you can then use =Indirect() to deal with, if need be.

Formula doesn't recognize cell reference - Dynamic range

I have a SUMIFS formula with which I am trying to build a dynamic range in order to avoid a circular reference. As it must search and sum through all the range, it must not consider the line where the formula is placed.
Sheet - Example
So I wrote this formula:
SUMIFS((C1:ADDRESS(VALUE(ROW(C6))-1;COLUMN(C1));ADDRESS(VALUE(ROW(C6))+1;COLUMN(C1)):ADDRESS(COUNTA(C:C);COLUMN(C1)));(C1:ADDRESS(VALUE(ROW(C6))-1;COLUMN(A1));ADDRESS(VALUE(ROW(C6))+1;COLUMN(A1)):ADDRESS(COUNTA(C:C);COLUMN(A1)));A6;(B1:ADDRESS(VALUE(ROW(C6))-1;COLUMN(B1));ADDRESS(VALUE(ROW(C6))+1;COLUMN(B1)):ADDRESS(COUNTA(C:C);COLUMN(B1)));"X")
However, after the sum_range it doesn't recognize the cell references. It remains "black". I tried another formula with OFFSET but got the same issue.
Any ideia what is going on?
A quick note, I need a dynamic range because there might be new lines inserted afterwards or people might apply filters, so I cannot use a normal reference.
You cannot have the formula in the same column as the range to sum, in this case it would cause a circular reference.
Use INDEX and two SUMIFS, SUMIFS does not like disjointed ranges and ADDRESS/OFFSET/INDIRECT are volatile:
=SUMIFS($C$1:INDEX(C:C;ROW()-1);$A$1:INDEX(A:A;ROW()-1);A2;$B$1:INDEX(B:B;ROW()-1);B2)+SUMIFS(INDEX(C:C;ROW()+1):INDEX(C:C;MATCH(1E+99;C:C));INDEX(A:A;ROW()+1):INDEX(A:A;MATCH(1E+99;C:C));A2;INDEX(B:B;ROW()+1):INDEX(B:B;MATCH(1E+99;C:C));B2)

Excel array formula with wildcard

I have an array formula that refers to a drop down cell ($AG$7) to determine which cells to evaluate. This works well, however, I need to include an additional item in the drop down which is "All".
When this is selected, I want the array formula to use "*" to return all instances from the array, but i can't get it to work.
This is the formula I'm currently using;
={SUM(IF((tblSkillsMatrix[Role]=[#Role])*(INDIRECT("tblSkillsMatrix["&V$2&"]")=$AG$7),1,0))}
I've tried using
={SUM(IF((tblSkillsMatrix[Role]=[#Role])*(INDIRECT("tblSkillsMatrix["&V$2&"]")="*"&$AG$7),1,0))}
and
={SUM(IF((tblSkillsMatrix[Role]=[#Role])*(INDIRECT("tblSkillsMatrix["&V$2&"]")="*"&$AG$7&"*"),1,0))}
But these don't work.
Does anybody have any ideas?
Thanks
A explicit = comparison cannot use wildcards. COUTIFS and SUMIFS can. As far as I see, you want to count only (conditional sum 1 and 0).
Problem is, COUTIFS and SUMIFS will not deal with INDIRECT ranges. But INDIRECT can and should (because of its volatile bahavior) often replaced by INDEX- MATCH.
So:
=COUNTIFS(tblSkillsMatrix[role],[#role],INDEX(tblSkillsMatrix,,MATCH($V$2,tblSkillsMatrix[#Headers],0)),"*"&$AG$7)
If $AG$7 is empty then it counts independent of the column named in $V$2.
Btw.: Within a table (ListObject) this needs not be entered as a array formula.
This is not 100% replacement of your formula since it not works if $V$2 is empty and so no table column title is given. Your formula will then look at all columns but this is not possible using COUNTIFS where each additional range must have the same number of columns as the criteria_range1 argument. So if $V$2 shall also can be empty, then this will not work.
If so then you could use
{=SUM((tblSkillsMatrix[role]=[#role])*(LEFT(INDIRECT("tblSkillsMatrix["&$V$2&"]"),LEN($AG$7))=$AG$7))}
Advantage: both $V$2 and $AG$7can be empty.
Disadvantage: Volatile behavior of INDIRECT and this formula then must be a array formula even in a ListObject-table. It must be confirmed using Ctrl+Shift+Enter.

For an Excel Formula's variable taking a Range, input row number by the result of a formula

I'm trying to fill in this =SERIES function to populate a line plot in Excel 2007.
=SERIES($BB$1,$BB$2:$BB$16,$BC$2:$BC$16,1)
Now the range $BB$2:$BB$16 and the one that follows are set for illustration. However, my plot needs to find a new range each time dynamically since the number of data points my function returns are different each time.
I can get the number of data points with a =COUNTA(BB2:BB1000), then I can chuck this number (plus 1 to make reference right) into the spot where 16 is in this case. How would I reference the following string as a range?
="$BB$2:$BB$" & COUNTA(BB2:BB1000)
In the place of
=SERIES([Cell],[Range],[Range]...)
If I just input this Excel won't take it. I tried INDIRECT but it returns the value of a cell, and can't be used as a range
This can be done using INDEX to specify the range
$BB$2:INDEX($BB:$BB,COUNTA($BB:$BB)+1)
While it can also be done with OFFSET or INDIRECT they are both volitile, so using INDEX is better because its not volitile.
For completness:
Using OFFSET
OFFSET($BB$2,0,0,COUNTA($BB:$BB))
Using INDIRECT
$BB$2:INDIRECT("BB"&COUNTA($BB:$BB)+1)
While these all work for "normal" cell formulas, it seems they don't work directly in a chart SERIES formula. However, they can still be used by creating a Worksheet scoped named range, and using that in the SERIES formula.
Try using the INDIRECT function:)
say you have three cell that can dynamically calculate the address of your input range.
something like what you suggested and it is in the cell A1
="$BB$2:$BB$" & COUNTA(BB2:BB1000) ---> in cell A1
You can use the Indirect function like this:
=SERIES(INDIRECT(A1),[RANGE],[RANGE])
Hope this helps!

Resources