How to combine two formulas into one?

honkin

Active Member
Joined
Mar 20, 2012
Messages
385
Office Version
  1. 2016
Platform
  1. MacOS
I have 2 separate lines of code which both work fine, but I need to have them work together.

Here is the first line:
Code:
=IF(F19="","",IF(F19<3.5,L18*0.01,IF(F19<7.45,L18*0.006,IF(F19<11.1,L18*0.004,"0"))))

Here is the second line of code:

Code:
=IF(F19="","",IF(F19<3.5,$M$18*0.01,IF(F19<7.45,$M$18*0.006,IF(F19<11.1,$M$18*0.004,"0"))))

I need them each to be used depending on this criteria - IF L19>$M$18 I want the first formula used, but IF L19<=$M$18, I want the second formula used.

Writing each line separately wasn't such an issue, but for the life of me, I always get lost trying to combine a couple of functions like this.

Here is what I tried, but Excel tells me there are too many arguments

Code:
=IF(L19>$M$18,IF(F19="","",IF(F19<3.5,L18*0.01,IF(F19<7.45,L18*0.006,IF(F19<11.1,L18*0.004,"0",IF(L19<=$M$18,IF(F19="","",IF(F19<3.5,$M$18*0.01,IF(F19<7.45,$M$18*0.006,IF(F19<11.1,$M$18*0.004,"0"))))))))))

Any thoughts how to have it work as described above?

cheers
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Code:
=IF(L19>$M$18,IF(F19="","",IF(F19<3.5,L18*0.01,IF(F19<7.45,L18*0.006,IF(F19<11.1,L18*0.004,"0")))),IF(F19="","",IF(F19<3.5,$M$18*0.01,IF(F19<7.45,$M$18*0.006,IF(F19<11.1,$M$18*0.004,"0")))))
 
Upvote 0
Solution
Code:
=IF(L19>$M$18,IF(F19="","",IF(F19<3.5,L18*0.01,IF(F19<7.45,L18*0.006,IF(F19<11.1,L18*0.004,"0")))),IF(F19="","",IF(F19<3.5,$M$18*0.01,IF(F19<7.45,$M$18*0.006,IF(F19<11.1,$M$18*0.004,"0")))))
Hi diddi

Thanks for your reply

Apologies for that. With it not being a VBA macro, I wouldn't have been sure where to indent, but I'll try and have it on multiple lines if it helps

Code:
=IF(L19>$M$18,IF(F19="","",IF(F19<3.5,L18*0.01,IF(F19<7.45,L18*0.006,IF(F19<11.1,L18*0.004,"0",
IF(L19<=$M$18,IF(F19="","",IF(F19<3.5,$M$18*0.01,IF(F19<7.45,$M$18*0.006,IF(F19<11.1,$M$18*0.004,"0"))))))))))

I hope this makes it easier to see the quite long line

cheers
 
Upvote 0
i posted the correction previously
 
Upvote 0
See if this more compact form does what you want. I believe that it produces the same results as the post #2 formula (except I have assumed it acceptable, possibly preferred, that this returns the number 0 rather than the text "0" when those conditions are met)

Excel Formula:
=IF(F19="","",LOOKUP(F19,{0,3.5,7.45,11.1},{0.01,0.006,0.004,0})*IF(L19>$M$18,L18,$M$18))

BTW, note that the forum has specific tags for worksheet formulas now. :)
1612764922506.png
 
Upvote 0
See if this more compact form does what you want. I believe that it produces the same results as the post #2 formula (except I have assumed it acceptable, possibly preferred, that this returns the number 0 rather than the text "0" when those conditions are met)

Excel Formula:
=IF(F19="","",LOOKUP(F19,{0,3.5,7.45,11.1},{0.01,0.006,0.004,0})*IF(L19>$M$18,L18,$M$18))

BTW, note that the forum has specific tags for worksheet formulas now. :)
View attachment 31522
Thanks for your reply

This code only looks at the condition L19>$M$18 It does not include L19<=$M$18

In the end, this was the code which combined it all perfectly
=IF(L18>$M$18, IF(AND(F19="",L18>$M$18),"",IF(F19<3.5,L18*0.01,IF(F19<7.45,L18*0.006,IF(F20<11.1,L18*0.004,"0")))), IF(L18<=$M$18, IF(AND(F19="",L18<=$M$18),"",IF(F19<3.5,$M$18*0.01,IF(F19<7.45,$M$18*0.006,IF(F19<11.1,$M$18*0.004,"0")))), ""))

Thanks again
 
Upvote 0
Hi,

Just want to point out:

Thanks for your reply diddi. That code handles L19>$M$18 only. It does not do anything for L19<=$M$18
cheers

Thanks for your reply

This code only looks at the condition L19>$M$18 It does not include L19<=$M$18

Thanks again

Both of these suggestions will work, the formula does Not need to test Both L19>$M$18 and L19<=$M$18,
You Only need to test for 1 of those conditions, if L19 is > M18, then obviously, L19 can Not be <= M18, or vice versa.
 
Upvote 0
In the end, this was the code which combined it all perfectly

=IF(L18>$M$18, IF(AND(F19="",L18>$M$18),"",IF(F19<3.5,L18*0.01,IF(F19<7.45,L18*0.006,IF(F20<11.1,L18*0.004,"0")))), IF(L18<=$M$18, IF(AND(F19="",L18<=$M$18),"",IF(F19<3.5,$M$18*0.01,IF(F19<7.45,$M$18*0.006,IF(F19<11.1,$M$18*0.004,"0")))), ""))

Are you sure that formula is doing what you want?
If so, then your original question was not correct because in post #1 you were comparing L19 to $M$18 but above you are comparing L18 to $M$18

IF L19>$M$18 I want the first formula used, but IF L19<=$M$18,
 
Upvote 0
Are you sure that formula is doing what you want?
If so, then your original question was not correct because in post #1 you were comparing L19 to $M$18 but above you are comparing L18 to $M$18
Cheers Peter, a typo only. In the end, the row for L will change as it is copied down; the only absolute being $M$18. L19 was just the row I copied the original from. The data in this sheet only starts in row 18. The original question was correct and was unanswered. I found the correct formula and posted it back here in case it helped anyone else

cheers
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,169
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top