Need a formula to compare one cell to a range, then depending on the result multiply to another cell

katryte623

New Member
Joined
May 30, 2018
Messages
5
I'm going to explain this as easy as I possibly can. Cell Z4 has a fuel amount. Let's say $2.50. If that amount falls within this range, then it will multiply by that percentage. So if somebody where to change the number in Z4, the result would update. The result is going in cell Z10.

Now once the fuel surcharge is calculated, I also need the fuel calculated which is a simple Y10*1.65.

So my original calculation was:
=IF(AND(Z4>=A42,Z4<B42),Z4*D42,IF(AND(Z4>=A43,Z4<B43),Z4*D43,IF(AND(Z4>=A44,Z4<B44),Z4*D44,IF(AND(Z4>=A45,Z4<B45),Z4*D45,IF(AND(Z4>=A46,Z4<B46),Z4*D46)*IF(AND(Z4>=A47,Z4<B47),Z4*D47,IF(AND(Z4>=A48,Z4<B48),Z4*D48,IF(AND(Z4>=A49,Z4<B49),Z4*D49,IF(AND(Z4>=A50,Z4<B50),Z4*D50,IF(AND(Z4>=A51,Z4<B51),Z4*D51,IF(AND(Z4>=A52,Z4<B52),Z4*D52,IF(AND(Z4>=A53,Z4<B53),Z4*D53,IF(AND(Z4>=A54,Z4<B54),Z4*D54,IF(AND(Z4>=A55,Z4<B55),Z4*D55)))))))))))))+(X10*1.65)

but that did not work


column A column B column D
row 42 $2.60 $2.69 1%
row 43 $2.70 $2.79 2%
row 44 $2.80 $2.89 3%
row 45 $2.90 $2.99 4%
row 46 $3.00 $3.09 5%
row 47 $3.10 $3.19 6%
row 48 $3.20 $3.29 7%
row 49 $3.30 $3.39 8%
row 50 $3.40 $3.49 9%
row 51 $3.50 $3.59 10%
row 52 $3.60 $3.69 11%
row 53 $3.70 $3.79 12%
row 54 $3.80 $3.89 13%
row 55 $3.90 $3.99 14%

Thank you!
 

Some videos you may like

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

katryte623

New Member
Joined
May 30, 2018
Messages
5
The formula did not copy correctly, its actually this but a longer continuance =IF(AND(Z4>=A42,Z4<B42),Z4*D42,IF(AND(Z4>=A43,Z4<B43),Z4*D43
 

jtakw

Well-known Member
Joined
Jun 29, 2014
Messages
5,146
Hi,

Put an EXTRA SPACE in front of ALL the "less than" < symbols in your formula so it'll show properly.
 

katryte623

New Member
Joined
May 30, 2018
Messages
5
ok so I tried a different, shorter way:

=($X$10*((SUMPRODUCT(($Z$4>=$A42:$A55)*($Z$4<=$B42:$B55)*$Z$4*($D42:$D55)))))

(the formula looks right to me, I hope when I post all of the symbols don't go away)
 

jtakw

Well-known Member
Joined
Jun 29, 2014
Messages
5,146
That's what I "thought" you were trying to do, below is "slightly" cleaned upped version of your SUMPRODUCT formula, and a LOOKUP alternative.
I don't think you were on the right tract with the Original IF/AND statement (although IF/AND could work, but I think the logic was not correct in your attempt).

<b></b><table cellpadding="2.5px" rules="all" style=";background-color: rgb(255,255,255);border: 1px solid;border-collapse: collapse; border-color: rgb(187,187,187)"><colgroup><col width="25px" style="background-color: rgb(218,231,245)" /><col /><col /><col /><col /><col /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: rgb(218,231,245);text-align: center;color: rgb(22,17,32)"><th></th><th>A</th><th>B</th><th>C</th><th>D</th><th>E</th><th>X</th><th>Y</th><th>Z</th><th>AA</th></tr></thead><tbody><tr ><td style="color: rgb(22,17,32);text-align: center;">4</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;">$3.00 </td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">9</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">10</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;">99</td><td style="text-align: right;;"></td><td style="text-align: right;;">$14.85 </td><td style="text-align: right;;">$14.85 </td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">41</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">42</td><td style="text-align: right;;">$2.60 </td><td style="text-align: right;;">$2.69 </td><td style="text-align: right;;"></td><td style="text-align: right;;">1%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">43</td><td style="text-align: right;;">$2.70 </td><td style="text-align: right;;">$2.79 </td><td style="text-align: right;;"></td><td style="text-align: right;;">2%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">44</td><td style="text-align: right;;">$2.80 </td><td style="text-align: right;;">$2.89 </td><td style="text-align: right;;"></td><td style="text-align: right;;">3%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">45</td><td style="text-align: right;;">$2.90 </td><td style="text-align: right;;">$2.99 </td><td style="text-align: right;;"></td><td style="text-align: right;;">4%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">46</td><td style="text-align: right;;">$3.00 </td><td style="text-align: right;;">$3.09 </td><td style="text-align: right;;"></td><td style="text-align: right;;">5%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">47</td><td style="text-align: right;;">$3.10 </td><td style="text-align: right;;">$3.19 </td><td style="text-align: right;;"></td><td style="text-align: right;;">6%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">48</td><td style="text-align: right;;">$3.20 </td><td style="text-align: right;;">$3.29 </td><td style="text-align: right;;"></td><td style="text-align: right;;">7%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">49</td><td style="text-align: right;;">$3.30 </td><td style="text-align: right;;">$3.39 </td><td style="text-align: right;;"></td><td style="text-align: right;;">8%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">50</td><td style="text-align: right;;">$3.40 </td><td style="text-align: right;;">$3.49 </td><td style="text-align: right;;"></td><td style="text-align: right;;">9%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">51</td><td style="text-align: right;;">$3.50 </td><td style="text-align: right;;">$3.59 </td><td style="text-align: right;;"></td><td style="text-align: right;;">10%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">52</td><td style="text-align: right;;">$3.60 </td><td style="text-align: right;;">$3.69 </td><td style="text-align: right;;"></td><td style="text-align: right;;">11%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">53</td><td style="text-align: right;;">$3.70 </td><td style="text-align: right;;">$3.79 </td><td style="text-align: right;;"></td><td style="text-align: right;;">12%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">54</td><td style="text-align: right;;">$3.80 </td><td style="text-align: right;;">$3.89 </td><td style="text-align: right;;"></td><td style="text-align: right;;">13%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">55</td><td style="text-align: right;;">$3.90 </td><td style="text-align: right;;">$3.99 </td><td style="text-align: right;;"></td><td style="text-align: right;;">14%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr></tbody></table><p style="width:5.6em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid rgb(187,187,187);border-top:none;text-align: center;background-color: rgb(218,231,245);color: rgb(22,17,32)">Sheet64</p><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: rgb(255,255,255)" ><tr><td style="padding:6px" ><b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: rgb(255,255,255);border-collapse: collapse; border-color: rgb(187,187,187)"><thead><tr style=" background-color: rgb(218,231,245);color: rgb(22,17,32)"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">Z10</th><td style="text-align:left">=$X$10*SUMPRODUCT(<font color="Blue">(<font color="Red">$Z$4>=$A42:$A55</font>)*(<font color="Red">$Z$4<=$B42:$B55</font>)*$Z$4*(<font color="Red">$D42:$D55</font>)</font>)</td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">AA10</th><td style="text-align:left">=$X$10*LOOKUP(<font color="Blue">$Z$4,$A42:$A55,$D42:$D55</font>)*$Z$4</td></tr></tbody></table></td></tr></table><br />
 

katryte623

New Member
Joined
May 30, 2018
Messages
5
I see how you cleaned up the formula! Thanks! So I tried it and in my X10 I have 125 and in Z4 I have $3.307. So when I enter the formula in, the result that pops up is $33.07. But if you simply take 125 x 8% (since $3.307 falls into the 8% category - line 49) the result is $10.00
 

jtakw

Well-known Member
Joined
Jun 29, 2014
Messages
5,146
Then why do you have *Z4 in your formula in Post #4 ???

If all you want is X10 ( 125 ) * 8%, just take out *Z4 in the formulas:

<b></b><table cellpadding="2.5px" rules="all" style=";background-color: rgb(255,255,255);border: 1px solid;border-collapse: collapse; border-color: rgb(187,187,187)"><colgroup><col width="25px" style="background-color: rgb(218,231,245)" /><col /><col /><col /><col /><col /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: rgb(218,231,245);text-align: center;color: rgb(22,17,32)"><th></th><th>A</th><th>B</th><th>C</th><th>D</th><th>E</th><th>X</th><th>Y</th><th>Z</th><th>AA</th></tr></thead><tbody><tr ><td style="color: rgb(22,17,32);text-align: center;">4</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;">$3.307 </td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">9</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">10</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;">125</td><td style="text-align: right;;"></td><td style="text-align: right;;">$10.00 </td><td style="text-align: right;;">$10.00 </td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">41</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">42</td><td style="text-align: right;;">$2.60 </td><td style="text-align: right;;">$2.69 </td><td style="text-align: right;;"></td><td style="text-align: right;;">1%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">43</td><td style="text-align: right;;">$2.70 </td><td style="text-align: right;;">$2.79 </td><td style="text-align: right;;"></td><td style="text-align: right;;">2%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">44</td><td style="text-align: right;;">$2.80 </td><td style="text-align: right;;">$2.89 </td><td style="text-align: right;;"></td><td style="text-align: right;;">3%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">45</td><td style="text-align: right;;">$2.90 </td><td style="text-align: right;;">$2.99 </td><td style="text-align: right;;"></td><td style="text-align: right;;">4%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">46</td><td style="text-align: right;;">$3.00 </td><td style="text-align: right;;">$3.09 </td><td style="text-align: right;;"></td><td style="text-align: right;;">5%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">47</td><td style="text-align: right;;">$3.10 </td><td style="text-align: right;;">$3.19 </td><td style="text-align: right;;"></td><td style="text-align: right;;">6%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">48</td><td style="text-align: right;;">$3.20 </td><td style="text-align: right;;">$3.29 </td><td style="text-align: right;;"></td><td style="text-align: right;;">7%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">49</td><td style="text-align: right;;">$3.30 </td><td style="text-align: right;;">$3.39 </td><td style="text-align: right;;"></td><td style="text-align: right;;">8%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">50</td><td style="text-align: right;;">$3.40 </td><td style="text-align: right;;">$3.49 </td><td style="text-align: right;;"></td><td style="text-align: right;;">9%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">51</td><td style="text-align: right;;">$3.50 </td><td style="text-align: right;;">$3.59 </td><td style="text-align: right;;"></td><td style="text-align: right;;">10%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">52</td><td style="text-align: right;;">$3.60 </td><td style="text-align: right;;">$3.69 </td><td style="text-align: right;;"></td><td style="text-align: right;;">11%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">53</td><td style="text-align: right;;">$3.70 </td><td style="text-align: right;;">$3.79 </td><td style="text-align: right;;"></td><td style="text-align: right;;">12%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">54</td><td style="text-align: right;;">$3.80 </td><td style="text-align: right;;">$3.89 </td><td style="text-align: right;;"></td><td style="text-align: right;;">13%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">55</td><td style="text-align: right;;">$3.90 </td><td style="text-align: right;;">$3.99 </td><td style="text-align: right;;"></td><td style="text-align: right;;">14%</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr></tbody></table><p style="width:5.6em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid rgb(187,187,187);border-top:none;text-align: center;background-color: rgb(218,231,245);color: rgb(22,17,32)">Sheet64</p><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: rgb(255,255,255)" ><tr><td style="padding:6px" ><b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: rgb(255,255,255);border-collapse: collapse; border-color: rgb(187,187,187)"><thead><tr style=" background-color: rgb(218,231,245);color: rgb(22,17,32)"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">Z10</th><td style="text-align:left">=$X$10*SUMPRODUCT(<font color="Blue">(<font color="Red">$Z$4>=$A42:$A55</font>)*(<font color="Red">$Z$4<=$B42:$B55</font>)*(<font color="Red">$D42:$D55</font>)</font>)</td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">AA10</th><td style="text-align:left">=$X$10*LOOKUP(<font color="Blue">$Z$4,$A42:$A55,$D42:$D55</font>)</td></tr></tbody></table></td></tr></table><br />
 

jtakw

Well-known Member
Joined
Jun 29, 2014
Messages
5,146
You're welcome, welcome to the forum.

No problem at All, glad to help.
 

Watch MrExcel Video

Forum statistics

Threads
1,095,221
Messages
5,443,168
Members
405,219
Latest member
CraneS

This Week's Hot Topics

  • Copy entire row if CountA <>0 to another sheet
    [B]I want to copy entire row if CountA <>0 for column J7:AM7 (headers on J6:AM6) and so on till the last used cell is column D and paste the...
  • Select last used Row in Table
    I have created a Table in a Worksheet which is locked to prevent user errors and protect formula. Some of the cells require freetext entries which...
  • excel workbook: do not allow certain file name
    Hello all, Don't think this has ever been asked before, but how do I restrict file save [Before_Save Event] if the name of the file being saved...
  • fixing problem autofilter
    hello i need help about my code when i search by code in textbox it doesn't show anything this is my data [ATTACH type="full"...
  • “Weight”
    Hi, i’ve got a long sheet filled with weights such as kg,g,L & ml. i can build a formula to convert kg into g and liter into ml. How ever, my...
  • How to capitalize everything before a certain character?
    In column A, I have some text: Hello good day.mp3 Hello good day.flac etc. I'd like to capitalize everything before the period. I don't need the...
Top