Microsoft Excel Putting a Function in an IF function - excel

I'm writing an IF function, and one of the [If_value_False] slots needs to be a random Function.
It works fine, but once the random formula is posted, the cell dosn't randomize, the IF function behaves as if whatever is in the value true has to be text, not a forumla.
Here's the function I've got:
=IF(ISBLANK(A2),"","=rand()")
If A2 is blank, this function should leave everything blank too whenever it's placed
If A2 is not blank, it should add a random function. That works up to there. The cell dosn't follow the =RAND() function.
How can I fix this?

Remove the quotes around the RAND() function
=IF(ISBLANK(A2),"",RAND())

I think your formula works as expected - it sets the displayed contents of the cell to the text "=rand()". If you want to set it to an actual function, I believe you have to do it from VBA using the notation
ActiveCell.Formula = "=rand()".

Related

Large function with dynamic array

I created this worksheet function and it works perfectly.
=LARGE({1;2;3;4;5;6;7;8;9;10;11;12;13;14;0;16;0;0;0;20;21;0;0},1)
The problem is how I created it. I started out with the function below which, unfortunately, does not work. It returns 0 instead of 21. That is unfortunate because it's precisely this function that I need.
=LARGE(ISBLANK(R$1:R23)*ROW(R$1:R23),1)
I converted the function I want to the function that works by selecting ISBLANK(R$1:R23)*ROW(R$1:R23) in the formula bar and pressing F9. Of course, this action merely displays the array specified by the formula. Therefore the working function and the not working function are technically identical. If you can't tell me how that can be then please try telling me why it is so.
Of course, I tried all the remedies that appeared "obvious". I tried entering the formula as an array formula (no need in Excel 365). I added -- before the ISBLANK function and tried that with the function in parentheses. All to no avail.
BTW, my purpose is to use the number of the blank sheet row above the cell with the formula in an OFFSET function to return a value from another column in that row. Imagine a block of cells with a title and wanting to reference the title row from any cell in the block, where the title row is identifiable because it has blank cells in the columns where the block has data.

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.

Is there a formula to look inside another cell's formula?

What I am working on is a quality-assurance spreadsheet, designed to analyse and quality check another spreadsheet for any errors in it's output and it's formulas.
On that latter note, I want to know if there's a formula that can inspect a cell (which also contains another formula) and return true or false if it contains a certain string of text, that is PART OF THE FORMULA itself.
For example, say in Cell A1 the formula is: =CEILING.PRECISE(B4) and equals 3.
I want to find out if the formula contains the word "Precise", which would then return TRUE. Another example being to see if the formula contains the string "B4" which would also return TRUE.
Depending on what Excel version you use....
Excel 2013/2016:
Make use of the build-in =FORMULATEXT() function. The function will return the formula of the referenced cell as text string. As such you could nest this in an =IF(...) statement.
Lower Excel version:
Make use of an UDF to accomplish the same effect. This doesn't have to be complicated. A simple UDF like below does the job.
Function FORMULATEXT(CL As Range)
FORMULATEXT = CL.Formula
End Function
The Answer of JvdV is already giving you everything you need about transforming the formula in a string.
In addition to this you can also use the FIND function to find if the word "PRECISE" is inside your formula.
=IF(FIND("PRECISE";FORMULATEXT(A1);1)>0;"TRUE";"FALSE")
Of course finding if B4 is inside would just be a small change after.

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)

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

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)

Resources