View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joeu2004[_2_] joeu2004[_2_] is offline
external usenet poster
 
Posts: 829
Default Formula works in google sheets but not in Excel, how to make it works?

"Pat" wrote:
=IF(D2="","",LOOKUP(D2,{0,4.99,9.99,24.99,99.99,14 99.99},
{"1","1.5","2.5",D2*0.1,(0.05*(D2-100))+10,(0.03*(D2-1500))+80}))
This formula works in google sheets but not in Excel on my PC.
How to make it works on Excel? "Using Excel 2007"


Try:

=IF(D2="","",CHOOSE(MATCH(D2,{0,4.99,9.99,24.99,99 .99,1499.99}),
"1","1.5","2.5",D2*0.1,(0.05*(D2-100))+10,(0.03*(D2-1500))+80))

However, at a minimum, I think the following is better:

=IF(D2="","",CHOOSE(MATCH(D2,{0,4.99,9.99,24.99,99 .99,1499.99}),
1,1.5,2.5,D2*0.1,0.(05*(D2-100))+10,(0.03*(D2-1500))+80))

I removed the double-quotes around the first 3 results so the formula
returns __numeric__ 1, 1.5 and 2.5 instead of __text__ "1", "1.5" and "2.5".
I presume that is what you intended.

Moreover, if D2 is calculated (a formula), the following might be more
reliable:

=IF(D2="","",CHOOSE(MATCH(ROUND(D2,2),
{0,4.99,9.99,24.99,99.99,1499.99}),
1,1.5,2.5,D2*0.1,0.(05*(D2-100))+10,(0.03*(D2-1500))+80))

The point is: D2 might __appear__ to be 4.99 due to formatting (e.g. Number
with 2 decimal places), but its __actual__ value might be less, for example
4.989.

In that case, you need to use ROUND(...,2) if you want to treat D2 as it
__appears__ (4.99).

Alternatively, you might use ROUND(...,2) in the formula in D2 instead.
Whether or not that is correct to do depends on the design of your
worksheet.

That is true for Google Sheets as well as Excel.