Using "INDIRECT" function in the "SUMPRODUCT" formula for True/False Cell Reference - excel

This is the formula that I am currently using:
=SUMPRODUCT((INDIRECT("A2"):INDIRECT("A"&(ROW()-1))=A359)*1)
It works great, but I would like to use this instead:
=SUMPRODUCT((INDIRECT("A2"):INDIRECT("A"&(ROW()-1))=INDIRECT("A"&(ROW())))*1)
Unfortunately I get a #VALUE!. What am I doing wrong? Both INDIRECT("A"&ROW(())) and A359 return the same value, so I'm not sure why this won't work.
The reason I am not using a simple COUNTIF function is because I stripped my formula of all unnecessary components and only left the part that I am having trouble with (i.e. I need to use the SUMPRODUCT formula and a COUNTIF formula will not work)
Thanks in advance!

I'm not sure why you need INDIRECT instead of ordinary cell references but the specific problem here is that ROW function returns an "array", even when it returns a single value, e.g. it returns {"x"} rather than just "x" - and in some circumstances Excel can't process that.
Try wrapping the second ROW function in a SUM function - the value doesn't change but it gets rid of the array, i.e.
=SUMPRODUCT((INDIRECT("A2"):INDIRECT("A"&(ROW()-1))=INDIRECT("A"&SUM(ROW())))*1)
This will eliminate #VALUE! eror while leaving the essential structure of your formula unchanged

Try this one:
=SUMPRODUCT((($A$2:INDEX($A:$A,ROW()-1))=INDEX($A:$A,ROW()))*1)
it gives you the same result.
But above formula is volatile. Instead I would use next one, say in B3 :
=SUMPRODUCT((($A$2:$A2)=$A3)*1)

Related

Combining IFERROR and LEFT Formulas

I have a formula that looks like this
=IFERROR(B83,"OPEN")
So if a certain cell has an error it changes it to OPEN, but if it doesn't then it returns the values within that cell.
I am trying to make the cell also short the text that is being returned to 7 characters.
I made this formula:
IFERROR(B83,"OPEN"),AND(LEFT(B83,7))
However it does not work and instead returns an "NA".
Appreciate any help.
Try
IFERROR(LEFT(B83,7),"OPEN")
You need to put your desired result as the first argument of IFERROR.

Inserting an INDIRECT into another formula to replace fixed values

I'm trying to do the following.
Take a value in a defined cell
Look up that value on another sheet called 'Updates'.
Look across the row for the last non-empty cell
Look up from there and return the header.
I know that if there was a defined range, the following formula works great for the last two steps.
=LOOKUP(2,1/(Updates!B3:E3<>0),Updates!B2:E2)
However I tried to make it more flexible with INDIRECT and came up with the abomination of a formula which I intended to just copy down.
=LOOKUP(2,1/INDIRECT("Updates!B"&B5+2&":S"&B5+2<>0),Updates!$B$2:$S$2)
However this just returns a #REF error. Is this type of thing not possible or is there a simpler way to go about it?
Thanks
I think you're not closing the INDIRECT statement before making the <>0 test - so move that bracket to the left and it should work; ie
= LOOKUP(2,1/INDIRECT("Updates!B"&B5+2&":S"&B5+2) <>0, Updates!$B$2:$S$2)

IF function with two cell ranges

I have two sheets with the same line of cells, for example, A1:A5.
I need to check if the value of every cell in Sheet1!A1:A5 is equal to Sheet2!A1:A5 but the hitch is the values will be letters, and all values are different. Simply typing the formula got me a #VALUE! error.
I know I can just write the formula:
=IF(Sheet1!A1=Sheet2!A1;1;0)
and then simply retype it in a number of cells with different values, but I'm looking for a way to shorten the formula.
Any suggestions?
To shorten the formula use array function. With that you will be able to check the whole range at once.
=IF(AND(Sheet1!A1:A5=Sheet2!A1:A5);1;0)
After typing the formula press Ctrl+Shift+Enter instead of just Enter key to confirm array formula.
This one is a little shorter
=(Sheet1!$A1=Sheet2!$A1)
You could use
AND(EXACT(Sheet1!A1, Sheet2!A1), EXACT(Sheet1!A2, Sheet2!A2), EXACT(Sheet1!A3, Sheet2!A3), EXACT(Sheet1!A4, Sheet2!A4), EXACT(Sheet1!A5, Sheet2!A5))
But in the following way:
Have a separate column with the code (let's say, column G)
EXACT(Sheet1!$A1, Sheet2!$A2)
To the column next to that, have a single cell with the code
AND(G1:G5)
Use the AND() function:
IF(AND(Sheet1!A1=Sheet2!A1,Sheet1!A2=Sheet2!A2,Sheet1!A3=Sheet2!A3,Sheet1!A4=Sheet2!A4,Sheet1!A5=Sheet2!A5),1,0).
EDIT
Not realy sure about your aim,
If you want it short because it is too difficult to write the above function, then try the method below:
=IF(CONCATENATE(Sheet2!A1,Sheet2!B1,Sheet2!C1,Sheet2!D1,Sheet2!E1)=CONCATENATE(Sheet1!A1,Sheet1!B1,Sheet1!C1,Sheet1!D1,Sheet1!E1),1,0)
But this is not without catch, it could return false positive. So use it with care. To overcome the false positive, I could only make the formula longer (but still relatively easy to write out).
=IF(CONCATENATE(Sheet2!A1,"|",Sheet2!B1,"|",Sheet2!C1,"|",Sheet2!D1,"|",Sheet2!E1)=CONCATENATE(Sheet1!A1,"|",Sheet1!B1,"|",Sheet1!C1,"|",Sheet1!D1,"|",Sheet1!E1),1,0)

Excel If formula not evaluating correctly?

I have an IF formula that is evaluating two cells with data returned from other formulas.
=IF(B5>D5,D5,B5)
Seems simple enough, right? However, when I attempt to use it, it seems to be evaluating the formulas in the cells instead of evaluating the values being returned.
I.E.: If B5 returns 414 and D5 returns 416, I get 416 instead of 414.
What am I missing here?
In my testing, your formula worked for me. Are you trying to display the lower number of the cells? If so, try this
=MIN(B5,D5)
While checking out my VLOOKUP formulas in the calculator I found an interesting fact. VLOOKUP returns all answers as text. So, in order to use the numerical value, place the cell inside the VALUE() function.
=IF(VALUE(B5)>D5,D5,VALUE(B5))
Voila! Works now!
Alternatively, you can place the VLOOKUP inside the VALUE function.
Thanks for your help guys!

ROW() function behaves differently inside SUM() and SUMPRODUCT()

Problem definition:
Enter any number in cell A1. Now try the following formulae anywhere on first row.
=SUM(INDIRECT("A"&ROW()))
and
=SUMPRODUCT(INDIRECT("A"&ROW()))
The first formula evaluates, the second one gives a #VALUE error.
This is caused by the ROW() function behaving differently inside SUMPRODUCT().
In the first formula, ROW() returns 1. In the second formula, row returns {1} (array of one length), even though the formula has not been entered as a CSE formula.
Why does this happen?
Background
I need to evaluate a formula of the type
=SUMPRODUCT(INDIRECT(*range formed by concatenation and using ROW()*)>1)
This is working out to an error. As a workaround to this issue, I now calculate ROW() in another cell (in the same row, obviously) and concatenate that inside my INDIRECT(). Alternately, I also have tried encapsulating it inside a sum function, like SUM(ROW()), and that works as well.
I would sure appreciate it if someone could explain (or point me to a resource that can explain) why ROW() returns an array inside SUMPRODUCT() without being CSE entered.
Interesting question. There are subtle issues here which I haven't seen documented.
It seems INDIRECT("A"&ROW()) returns an array consisting of one element which is a reference to a cell - not the value in that cell. Many functions cannot resolve this type of data correctly but a few functions such as N and T can "dereference" the array and return the underlying value.
Take this case where there are two elements in the array:
=SUM(N(INDIRECT("A"&ROW(1:2))))
This returns A1+A2 when array entered but it only returns A1 when entered normally. However changing ROW(1:2) to {1;2} in this formula returns the correct result when entered normally. The equivalent SUMPRODUCT formula returns A1+A2 whether array entered or not.
This may be related to how the arguments are registered in the function. According to http://msdn.microsoft.com/en-us/library/bb687900.aspx there are essentially two methods to register function arguments to handle Excel data types:
Type R/U: "Values, arrays, and range references."
Type P/Q: "Excel converts single-cell references to simple values and multi-cell references to arrays when preparing these arguments."
SUM arguments seem to conform with type R/U while SUMPRODUCT arguments behave like type P/Q. Array-entering the SUM formula above forces the range reference argument in ROW to be evaluated as an array whereas this happens automatically with SUMPRODUCT.
Update
After a little more investigation, here's further evidence that might support this theory. Based on the link in the comment, the formula =SUM((A1,A2)) gives the same values as:
?executeexcel4macro("CALL(""Xlcall32"",""Excel4"",""2JRJR"",4,,1,(!R1C1,!R2C1))")
Registering the last argument as type P by changing 2JRJR to 2JRJP gives an error in this case but does allow for single area ranges like !R1C1:!R2C1. On the other hand, changing the 4 (xlfsum) to 228 (xlfsumproduct) only allows single area references either way it's called just like SUMPRODUCT.
As ROW() returns an array, use INDEX to get the 1st element.
You example then becomes: =SUMPRODUCT(INDIRECT("A"&INDEX(ROW(),1)))
I don't think ROW() behaves differently here, it returns an array in both cases. I assume that SUM and SUMPRODUCT treat that array differently - not sure why.
Many functions or combinations of them return arrays - you don't need CTRL+SHIFT+ENTER to make that happen, you only need CSE in many cases to process the arrays created.
I would just use INDEX in place of INDIRECT (which also benefits you by avoiding a volatile function), i.e.
=SUMPRODUCT(INDEX(A:A,ROW()))
....expanding that to your range this formula will count the number of values > 1 in a range in column A where x defines the start row and y the end row
=COUNTIF(INDEX(A:A,x):INDEX(A:A,y),">1")
x and y can be calculated by formulas
you can use SUMPRODUCT or COUNTIFS in a similar way if there are more conditions to add

Resources