Click here to Skip to main content
15,915,319 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have made a formula of IF function to see that, If the value is equal to what i want then, then take a value from cell A and multiply by cell B. A simple example if what i want to do is below. The below is a sample of a nested if function.

=IF(J15="3mm",B16*K15,IF(J15="4mm",B17*K15,IF(J15="5mm",B18*K15,IF(J15="10mm",B19*K15))))
J15 is the drop down menu with all the values
B16:B19 is the value i want to receive if J15 is true
And i want to multiple B16:B19 with K15

The problem is with the bigger formula below that has about 16 nested ifs. If i write the code it works fine but the moment i close excel and open it, This is written =#VALUE! instead of my code. Below is the problematic formula

C#
=IF(J28="1/2_Inch/1.5mm",$D$58*K28,IF(J28="3/4_Inch/1.2mm",$D$59*K28,IF(J28="3/4_Inch/1.5mm",$D$60*K28,IF(J28="1_Inch/1.2mm",$D$61*K28,IF(J28="1_Inch/1.5mm",$D$62*K28,IF(J28="1x2_Inch/1.2mm",$D$63*K28,IF(J28="1x2 Inch/1.5mm",$D$64*K28,IF(J28="1.5x1.5_Inch/1.5mm",$D$65*K28,IF(J28="1.5x1.5_Inch/2mm",$D$66*K28,IF(J28="2x2_Inch/1.5mm",$D$67*K28,IF(J28="2x2_Inch/2mm",$D$68*K28,IF(J28="3x3_Inch/3mm",$D$69*K28,IF(J28="3x3_Inch/4mm",$D$70*K28,IF(J28="4x4_Inch/4mm",$D$71*K28,IF(J28="4x4_Inch/5mm",$D$72*K28,IF(J28="4x4_Inch/6mm",$D$73*K28))))))))))))))))



Other details

1) The values such as 1/2_Inch/1.5mm & 3/4_Inch/1.2mm are all in one drop down menu
J28 is that drop down value

2) The cell D58 till D73 are the cells which have the value i want incase the J28 value is true
3) I am multiplying Cells from D:58 to D73 with K28.

Also strangely if i put this formula in windows excel it does not work at all, but it works in Mac if i put it all over again or if i just remove a few Quotation marks and put it back

I am using office 2016 mac and i also have windows 2016 excel

What I have tried:

I have tried to remove all spaces from the quotation marks but still does not work
Posted
Updated 6-May-16 1:33am

Instead of using nested IF use a VLOOKUP
VLOOKUP function - Office Support[^]
A lot simpler to see what is going on
 
Share this answer
 
First off, your function is incomplete.

Every IF function must have a condition, a true case and a false case. You last IF function: IF(J28="4x4_Inch/6mm",$D$73*K28) has no false case.

Just add a "#What?!?" or whatever as a false case. Even "" will work

Secondly, there is actually a SWITCH Function that would probably be better:
SWITCH function - Office Support[^]

You would write it like this:
=SWITCH(J28,"1/2_Inch/1.5mm",$D$58*K28,"3/4_Inch/1.2mm",$D$59*K28,"3/4_Inch/1.5mm", $D$60*K28,"1_Inch/1.2mm",$D$61*K28,"1_Inch/1.5mm",$D$62*K28,"1x2_Inch/1.2mm",$D$63*K28,"1x2 Inch/1.5mm",$D$64*K28,"1.5x1.5_Inch/1.5mm",$D$65*K28,"1.5x1.5_Inch/2mm",$D$66*K28,"2x2_Inch/1.5mm",$D$67*K28,"2x2_Inch/2mm",$D$68*K28,"3x3_Inch/3mm",$D$69*K28,"3x3_Inch/4mm",$D$70*K28,"4x4_Inch/4mm",$D$71*K28,"4x4_Inch/5mm",$D$72*K28,"4x4_Inch/6mm",$D$73*K28)

The pattern is as follows:
=SWITCH([SourceField],Case1,Value1[,CaseN,ValueN],Default)

In the select I wrote, the SourceField is J28, there are several Case Value pairs (such as "1/2_Inch/1.5mm",$D$58*K28) and a Default value of $D$73*K28


Hope that helps ^_^

Andy
 
Share this answer
 
There is no reason to have problem with this formula
VB
=IF(J28="1/2_Inch/1.5mm",$D$58*K28,IF(J28="3/4_Inch/1.2mm",$D$59*K28,IF(J28="3/4_Inch/1.5mm",$D$60*K28,IF(J28="1_Inch/1.2mm",$D$61*K28,IF(J28="1_Inch/1.5mm",$D$62*K28,IF(J28="1x2_Inch/1.2mm",$D$63*K28,IF(J28="1x2 Inch/1.5mm",$D$64*K28,IF(J28="1.5x1.5_Inch/1.5mm",$D$65*K28,IF(J28="1.5x1.5_Inch/2mm",$D$66*K28,IF(J28="2x2_Inch/1.5mm",$D$67*K28,IF(J28="2x2_Inch/2mm",$D$68*K28,IF(J28="3x3_Inch/3mm",$D$69*K28,IF(J28="3x3_Inch/4mm",$D$70*K28,IF(J28="4x4_Inch/4mm",$D$71*K28,IF(J28="4x4_Inch/5mm",$D$72*K28,IF(J28="4x4_Inch/6mm",$D$73*K28))))))))))))))))

But one can make it better because everything is multiply by k28, it can be moved to the end.
VB
=IF(J28="1/2_Inch/1.5mm",$D$58,IF(J28="3/4_Inch/1.2mm",$D$59,IF(J28="3/4_Inch/1.5mm",$D$60,IF(J28="1_Inch/1.2mm",$D$61,IF(J28="1_Inch/1.5mm",$D$62,IF(J28="1x2_Inch/1.2mm",$D$63,IF(J28="1x2 Inch/1.5mm",$D$64,IF(J28="1.5x1.5_Inch/1.5mm",$D$65,IF(J28="1.5x1.5_Inch/2mm",$D$66,IF(J28="2x2_Inch/1.5mm",$D$67,IF(J28="2x2_Inch/2mm",$D$68,IF(J28="3x3_Inch/3mm",$D$69,IF(J28="3x3_Inch/4mm",$D$70,IF(J28="4x4_Inch/4mm",$D$71,IF(J28="4x4_Inch/5mm",$D$72,IF(J28="4x4_Inch/6mm",$D$73))))))))))))))))*K28

If it is possible to build a table with 2 columns containing all the pairs of size and values, you can use VLOOKUPwhich will simplify the formula
.
Assuming $C$58:$C$73 is available with
VB
$C$58="1/2_Inch/1.5mm"
...
$C$73="4x4_Inch/6mm"

you need
VB
=VLOOKUP(j28, $C$58:$D$73, 2, FALSE)* K28
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900