I have multiple input values in excel that should be used to dynamically generate an output in a cell.
For example in cell B1:B15 I have 15 checkboxes, and in cell A1 I have a dropdown menu with multiple values. Now I want to take the value of cell A1 and then based on the checked boxes in B1:B15 I want to generate an output (a notition with an image). As you can imagine, there's quite a lot of possible ways in this 'graph'. What would be the easiest way to implement such a thing in excel, in such a manner that it is easy to expand upon?
So for example:
If (a1=="wood" and (b1==checked, b2==checked, b5==checked), "Output1")
If (a1=="wood" and (b1==checked, b5==checked, b7==checked), "Output2")
... etc.
I don't know of any way to manipulate images in excel just using formulas.
That being said, I think there might be a way to get a result similar to what you are looking for.
If you create a 2 column table of cells (I'm using c2:d5), first column checks column B for the specifics you want (ex: c2 will look at cells B1, B2, B3, and return "True" if they are all "Checked"), then all you have to do is create an output cell that says =vlookup("True",c2:d5,2,false), then it will return what you put in column d next to the check in column c.
If you want a default option if none of the conditions work out, put "True" on the last line of the table, instead of another condition. Vlookup finds the first matching condition, so as long as its the last option, it will only be found if none of the rest match "True".
if you want this to happen only if A1 = "Wood", then put a If statement around it. (=IF(A1 = "Wood", Vlookup(), [insert what you want if its not equal to "wood"]))
If you want a physical change to the cell you typed "wood" into, you can use conditional formatting: create a custom format, choose the format, type the formula as a true/false if statement. (There may be other ways to get it to work, but I don't know of any other way to make a conditional format), EX: =IF(AND($A$1="Wood",vlookup("True",c2:d5,2,false)=[result]),TRUE,FALSE)
Related
I am trying to develop a simple expiration date with conditional highlighting. I've set up the column I to an IF statement based on a logic test in column G, drawing value from Column A. Formula is currently:
=IF(G2="N", A2+7,A2+60)
Problem is, I'm making this for a complete excel newbie so I need it foolproof. I want column I to remain blank as long as either cells in the corresponding column A or G are blank (not relevant which, they'll both be filled together). I've tried a few nested and "AND" statements to no avail.
You need to use OR to test if either A2 or G2 is blank using the ISBLANK function:
=IF(OR(ISBLANK(A2),ISBLANK(G2)),"",IF(G2="N",A2+7,A2+60))
If so, you can return "" if either input is blank, and if both are populated then go ahead and use your original formula.
One option is to use COUNTA function to determine how many cells are populated and only use the IF function if the result is 2, e.g.
=IF(COUNTA(A2,G2)=2,IF(G2="N",A2+7,A2+60),"")
This is probably very easy for experienced user of excel, but I couldn't find a way to do this, so I asking this question.
I have particular range of cells, let's say E5:M5, only one cell of this range will contain 1, other will contain 0. I want to reference, first cell of that column (which contains label). I want to do this by using a formula in another cell. In the end, that another cell should have label name as its value.
I wanted to post image elaborating what I want, but it seems I can't do that.
Anyway, can anyone tell me how this can be done?
I'm going to assume you want to use a formula rather than VBA as it is not recommended for inexperienced Excel users to use VBA. Use this formula to determine the first column out of your set, which has "1" as a value:
=match(1,E5:M5,0)
If by 'label name' you mean you have a header or something (let's assume in row 4), you can use the index function to pull the value from the mirror set of rows above the match function, like so:
=index(E4:M4,match(1,E5:M5,0))
Can't believe I don't know this, but is there a way to avoid repeating a formula in an if statement if the logical test is dependent on it?
i.e.
=IF((SUMIFS formula)=0,"",SUMIFs formula)
I want to replace that SUMIFS function in the false scenario with something short that will tell it to just programmatically repeat the formula it originally tested for. Repeating the formula twice has to have detrimental effects on processing speed. Negligible, maybe, but want to go for best-practices here. Thanks.
You can force an error like #DIV/0! and then use IFERROR, e.g.
=IFERROR(1/(1/SUMIFS_formula),"")
You can assign a Name to a formula and use the Name..............See:
Assigning a name to a formula
Relevant excerpt -
For example, let's suppose we frequently use a formula like:
=SUM(A1:A100)-SUM(B1:B100) and this resides in A101 and is copied across many columns on row 101. It would be better in this case to
create a custom formula that does this in each cell on row 101. Here
is how;
1) Select cell A101 (this is vital).
2) Go to Insert>Name>Define and
in the "Names in workbook" box type: SalesLessCosts
3) Now click in
the "Refers to" box and type: =SUM(A1:A100)-SUM(B1:B100) then click
Add.
Now you can replace the formula in cell A101 with: =SalesLessCosts.
You can also copy this across row 101 and it will change its relative
references just as the formula =SUM(A1:A100)-SUM(B1:B100) would. The
reason it does this is all down to the fact we selected A101 before
going to Insert>Name>Define and used relative references in
=SUM(A1:A100)-SUM(B1:B100) when we added it to the "Refers to" box.
If all you need to do is hide zeroes, there is an easy way:
Select all cells where you wish to hide zeroes
Go into Custom Number Formatting
Set format to "General;General;"
The custom formatting has a structure of [positive numbers];[negative numbers];[zeroes]
By making the last part blank you are effectively hiding zeroes, but showing everything else.
The advantage over conditional formatting is that you can use this on any background.
A neat trick which I sometimes use is to hide the cell value completely by using a custom format of ";;;". This way you can put images inside the cells, like the conditional formatting ones, and not see the value at all.
Try using the SUBSTITUTE function like this :
=SUBSTITUTE( VLOOKUP( H4; $D$5:$E$8; 2; 0 ); $H$1; $I$1 )
Here is an example:
Here the formula I don't want to repeat twice is the VLOOKUP function.
The result of VLOOKUP is a string found in another table (ex : "Green").
I want to check if that string matches a specific string value in $H$1 (here, "Yellow").
If it does, SUBSTITUTE replaces it with$I$1 (the error string you want. Here, "FORBIDDEN").
If it doesn't, it displays the VLOOKUP result string (the normal authorized output, like "Green").
This is useful for me because my actual formula is quite long, so I don't want to write it twice.
I also dont want to use two different cells, because I'm already applying this formula on 10 columns, meaning I should add an extra 10 columns to make it work.
In some scenarios, MAX() or MIN() can do a wonderful job.
E.g., something like this:
=IF(SUMIFSformula>0,SUMIFSformula, 0)
Can be shortened to this:
=MAX(0,SUMIFSformula)
The LET formula can be used for this exact scenario. You can define the formula as a variable and then within that same cell you can reference the variable in your formula.
The LET formula format looks like this:
=LET(name,name_value,calculation)
SUMIFS Example
Here's how it would work with your SUMIF example so that you don't have to repeat the formula:
In this screenshot we have an array A1:B7. We want to sum the values (Col B) if the name in ColA is "apple".
For this we have a standard SUMIFS formula of
=SUMIFS(B1:B7,A1:A7,"apple")
The formula is showing in E2. The result is shown in E3.
To put this into the IF statement without having to repeat the formula we can use LET as shown in the screenshot.
We create a variable with the SUMIFS formula as the value of that variable. We then write our IF statement using the variable name instead of rewriting the formula multiple times.
=LET(name,name_value,calculation)
Variable name: sumapples
Variable value: SUMIFS(B1:B7,A1:A7,"apple")
Calculation: IF(sumapples=0,"",sumapples)
Put together in the LET function it looks like this:
=LET(sumapples,SUMIFS(B1:B7,A1:B7,"apple"),IF(sumapples=0,"",sumapples))
This LET function can be used in any Excel formula, and is very useful for shortening long formulas that have repetition.
Optional: Extra complexity
If you want to you can get extra complicated by naming multiple variables.
=LET(name,name_value,name2,name_value2,calculation)
Since Excel 2007, the IFERROR statement does what the OP asked. From the help file:
Description:
Returns a value you specify if a formula evaluates to an error; otherwise, returns the result of the formula. [italics mine]
Syntax:
IFERROR(value, value_if_error)
I've since realised that this was already answered by #barry houdini above.
Here is a hack - depending on whether you are just interested in the displayed value, or whether you need to use the value in another formula:
Put your SUMIF formula in the cell (without the IF part)
Create a conditional formatting rule which sets the font color to the background color when the cell value is 0
And hey presto, you get the desired result.
As I said - it's a hack, but it does prevent the double evaluation.
There is no "clean" solution that I am aware of.
I know there's several posts about this, here and other places, but I seem to get errors no matter which method I try.
I'm trying to fill an adjacent cell with a value based on the corresponding value from a list of values. For example, there's a list of Test -> Action pairs, defined in two columns. In another cell, I want to type in a value which exists in column B, and then fill the adjacent cell with the corresponding value in column A.
Here's my Sheet.
The columns "Actions" and "Tests (test groups)" define the corresponding values.
I'm using VLOOKUP in the "Test (test grop)" column (below the first two columns, from row 10 and down), to fill the cells when I'm entering a value in the "Action" value. Simple enough.
However, now I need this exact functionality in another sheet. I need to move the "Action" and "Test (test group)" columns - row 10 and down - to another sheet, and still reference the values in this sheet (row 2 - 6).
I've tried INDIRECT and a couple of other alternatives, and all give me either "#REF" or "#VALUE" in the cell where I use VLOOKUP.
Anyone able to explain how to do this, related to this example?
You need to add the worksheet name to your formula. Use single quotes if you have spaces or special characters in the name. Like this:
=VLOOKUP(A1,'sheet-name-with-dash'!$A$1:$B$9,2,FALSE)
may seem out of place, but whenever I see this kind of problems (in defining and using ranges) I think of the Excel option to define those ranges (like in Ctrl+F3, Name Manager).Showcase:
select your area: in your case A2:B6,
hit: Ctrl+F3,
name the range: i.e. LookupRange
use that range in Vlookup formula like: Vlookup($A12,LookupRange,2,0)
I do not use this on regular basis,but might get handy in a workbook with many sheets, ranges, formulas. Try this for fun at least.
Hope it helps.
This seems like such an obvious thing that excel must have this feature, I just can't find it.
How can I create a custom function without using VBA? (VBA is too big of a hammer and causes security warnings, etc).
For example, I have a spreadsheet with several very complex formulas. Each of these formulas are replicated in several columns. Each column has hundreds of entries, so each one is replicated hundreds of times. If I tweak something then I have to manually fill-down or copy my change from one column to another.
A simple one looks like this:
=(Payment1 - F$12)*12 + ($D21-H21)
But what I'd like to do is:
=MyFunction(f$12,$D21,H21)
And have the actual formula for "MyFunction" written just once someplace.
I've found a few things that come close to giving me what I want. For example, in tables Excel will automatically replicate changes in a formula down the rest of the column saving you the step of manually selecting the range and doing a "Fill Down".
It will also allow relative references off of named cells, which seems equivalent of a user-defined parameter-less functions.
if you can use text to create the formula, then you can define a name to evaluate the function.
In cell A2, create a name EvalAbove, and in Refers To, enter =evaluate(A1)
This way, you can construct a formula
e.g. B1 contains SUM, B2 contains =("="&B1&"(A2:A5)")
and in B3, you can then put =EvalAbove
This means that if you change the formula name in B1, then B2 will change to show the changed formula, and B3 will change to show the result.
Note that this still counts as a macro enabled workbook, but there's no VBA code, just named ranges
You can do this for the example you show if I interpret it correctly.
If not you may be able to rearrange things slightly to conform
your function has three parameters:
The first comes from row 12 of the current column
The second from column D of the current row
The third comes from the column two to the right of the current row
I assume Payment1 is a named variable already?
Set the cursor in say F21 and then define this name
MyFunction =(Payment1 - F$12)*12 + ($D21-H21)
This will set the parameters to come from the places shown
To understand this better switch to RC mode and type the formula as:
=(Payment1 - R12C)*12 + (RC4-RC[+2])
You can now propagate down the formula through the F coloumn
=MyFunction
and it will always use the values in the corresponding F12 column Dxx and column Hxx
If you drag the formula to the next column it will use G12, Dxx and Ixx
If you want to change the formula edit it in the define name space
This is a general exception to the rule that you cannot have non-vba UDFs in Excel. Often in Excel the things you want as 'arguments' to the function are actually in fixed places (rows or columns) that can be addressed relatively.
For example you often want to perform a udf on the cell to the left
So a udf giving the cuberoot of the cell to the left would be a named formula like this:
Cuberoot =(RC[-1])^(1/3)
Or in a1 form set the cursor in B1 and type =(A1)^(1/3)
And Excel will convert it internally to the RC form
For three args - use three columns
It works and does not suffer the volatility issue mentioned about evaluate()
Yes I know this is an old posting but it may help someone with the same issue.
Bob J.