Excel conditional nested function - excel

I am trying to write an Excel function in order to compare the values of two columns and write in a third column a specific value, dependent of that comparison. The conditions that need to be simultaneously met are the following:
IF A1 = 0 AND B1 = 1 THEN C1 = 2 IF A1 = 0 AND B1 = 2 THEN C1 = 1 IF A1 = 2 AND B1 = 1 THEN C1 = 3 IF A1 = 2 AND B1 = 2 THEN C1 = 4
Is it possible to achieve this with nested IF's in Excel?
Many thanks

So, based on what you state, this:
=if(and(a1=0,b1=1),2,if(and(a1=0,b1=2),1,if(and(a1=2,b1=1),3,if(and(a1=2,b1=2),4,"check"))))
Proving most cases:

What I would do, is to externalize those conditions. It helps you (and everyone else) whenever
your boss wants to know how your are calculating this specific value --> you simply show her the condition table (no need to look into the formula)
your boss (or the data itself) wants you to add another condition --> you simply add a new row to the conditions table (no need to make the formula longer)
...
The formula I use in Column C of the data table:
=IFERROR(FILTER(tblConditionC[C],(tblConditionC[A]=[#A]) *(tblConditionC[B]=[#B])),"no mapping")

This should do what you want:
=IF(A1=0,IF(B1=1,2,IF(B1=2,1,"Invalid Input")),IF(A1=2,IF(B1=1,3,IF(B1=2,4,"Invalid Input")),"Invalid Input"))

Related

Dependent cell value with multiple conditions in excel

I was hoping someone could lead me in right direction here.
Basically I am looking for a formula or VBA code to change the cell A1 value depending on multiple different conditions. The conditions are different name ranges ( in form of drop down list ) in different worksheets. So for example here are the 3 different conditions:
If the NameRange1 in sheet1 = “yes” then cell A1 = A otherwise do nothing
If NameRange2 in Sheet2 = 2 Then A1 = B otherwise A1 = C
If none of those conditions are meet then A1 = D
I am new to Excel and I know it’s quite messy but I was thinking of nested if statements with first two conditions nested inside true statement and last condition in false?
=IF(A1="",IF(condition1,IF(condition2),condition3))
Any help would be appreciated
From your comment, looks like this will work:
=IF(nameRange1="yes","A",IF(nameRange2="red","B",IF(nameRange2="black","C","D")))
If that is not exactly what you need, you can at least see the IF embedding pattern and adjust for your needs.

Excel - Referencing a formula operator from another cell

Is it possible to reference text from various cells to construct a formula in a different cell?
Example:
A1 = 1
A2 = >
A3 = 0
=IF(CONCATENATE(A1:A3),1,0) returns 1
This obviously returns an error, but I'm hoping there's a function that does something like this.
Also I'd like to avoid using if statements since I have quite a few values that can populate the reference cells. (EX: IF(A2="<",...,IF(A2=">",...)))

VLOOKUP Text that is not unique - Excel

I am trying to vlookup (bring back) all the products that are yes, but only the first result keeps coming back because the vlookup gets stuck on the first piece of data.
I am using much more data than the range below but please see below as example.
A1 = Yes B1 = Product 1
A2 = Yes B2 = Product 2
A3 = Yes C3 = Product 3
=vlookup("Yes",$A$1:$C$3,2,false)
It works if I take out the $ signs but then I just get repeat values.
I am guessing this needs a different function but am unsure what to use.
Thanks
Ian
Check this link and understand how that formula works. In your example, put this formula into cell D2 and press CTRL+SHIFT+ENTER and fill down using mouse:
=IFERROR(INDEX($B$1:$B$12, MATCH(0,IF("yes"=$A$1:$A$12,COUNTIF($D$1:D1, $B$1:$B$12),""), 0)),"")

Combining functions in Excel?

Please see my image,
I am need to count number of rows that have the cell value (in G column) = 1; but the values of column A and column B not equal another rows (not loop). For example: Row 4 have A4 = A3 = 16 and B4= B3 = 221 so we ignore (Row 6 is ignore, too).
Do you know what is the proper function ?
Thank you very much.
As per your image, use this one in I1 and drag it down:
=IF(AND(G1=1,COUNTIFS($A$1:$A1,$A1,$B$1:$B1,$B1)=1),"YES","NO")
and then in I8 you can use
=COUNTIF(I1:I6,"YES")
You can just do something like this, where you can add as many other conditionals as you need to the AND function.
=IF(AND(G4=1, NOT(A4=A3), NOT(B4=B3)),"True","False")
I'm having a little trouble following the logic in your question - the best solution is likely to write a custom VBA function and then call that function per cell. See www.cpearson.com/excel/writingfunctionsinvba.aspx

Excel - Sheet as a function

I have two excel sheets. The first contains a formula for calculation with one input cell (A1), and one output cell (B1). The formula for B1 could be B1 = A1 * 3 (example).
The second sheet contains various values in column A: A1 = 4; A2 = 9; A3 = 5 ... In corresponding column B of this sheet I'd like to get the result of B1 (first sheet) = A1 (second sheet) * 3 for each A (second sheet) input value.
Basically I'd like to treat the first sheet as a function, where A1 is the argument and B1 the result that is passed back to the second sheet's B column.
Sheet 2
A1 4 B1 12 (result from sheet 1)
A2 9 B2 27 (result from sheet 1)
...
Is it possible without macros?
This is built into Excel. In version 2003, use the Data, Table menu.
You can find many examples on the net. Here is one.
You can create such tables with either 1 or 2 entries (parameters).
I don't think so .....
If in B1 Sheet1 you have
3*A1
If you try this in Sheet2 B1
`=SUBSTITUTE(Sheet1!$B$1,"A1",A1)`
it will give
3*4, and Sheet2 B2 will be
3*9etc
But I don't see how you could coerce this to a numberic calculation with formulae without possibly some heavy duty formula string parsing to separate numbers from operators (which is unlikley to flex as desired if you change the entry in B1 Sheet 1)
[Update 2: but fwiw I have done it with a named range]
I used this range name
RngTest
=EVALUATE(3*INDIRECT("rc[-1]",FALSE))
This is a global range name so it will work on any sheet, more powerful than my prior OFFSET effort. It multiplies the cell to the immediate left by 3
so entering =RngTest in B1:B3 (and then in this new example C1:C3 as well)
gives the output you want
I think you want to use this in your sheet two column.
Sheet1!B1 * Sheet2!A1
Entirely without VBA: expect lots of pain, I won't go there. But...
To substantially reduce the amount of pain, you could actually use this one tiny VBA user-defined function (not technically a "macro"), basically just a wrapper to make VBA's Evaluate function available in worksheet formulas:
Function eval(myFormula As String)
eval = Application.Evaluate(myFormula)
End Function
You could then use it like this in cell B1 on sheet 2:
=eval(SUBSTITUTE(Sheet1!$B$1,"A1","A"&ROW()))
Note that this requires Sheet 1 cell B1 to contain A1*3 and not =A1*3, i.e. no equal sign. Maybe with a bit more fiddling around, it can be made to work even with the = sign there...
EDIT: Actually, if you format Sheet 1 cell B1 as Text before typing in the formula, this will work even if your formula starts with a =.
Is it possible without macros?
Yes!
You can now use =LAMBDA for this.
Define your function using the name manager, then reference it in your second sheet's formula.
See syntax at Introducing the LAMBDA function.
For more information about how to use the LAMBDA function, see the support documentation.

Resources