+ Reply to Thread
Results 1 to 10 of 10

Whats wrong with my code

  1. #1
    Registered User
    Join Date
    06-28-2012
    Location
    Glasgow
    MS-Off Ver
    Excel 2003
    Posts
    5

    Whats wrong with my code

    Hey - completely novice excel user trying to get my head round a line of algorithm...

    Im trying to tier an IF statement... basically over 100% you get 10% of a value, between 110-120% you get 20% of a value, and 120% you get 30% of a value.

    the 666 is a standard commission payment made after getting over 100% which is why its in every part.

    My code is like this...

    IF(F2<100, 0, IF(F2>=100 AND <110, (((E2-D2)*0.1)+666)), IF(F2>=110 AND <120, (((E2-D2)*0.2)+666)), (((E2-D2)*0.3)+666))

    Excell telling me its wrong - but I cant see why!!

    help please?

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Whats wrong with my code

    and isnt done like that it is like this =and(f2>100,f2<110)
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Registered User
    Join Date
    06-28-2012
    Location
    Glasgow
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Whats wrong with my code

    I think its something to do with the brackets, But im sure I bracketed it all together...

    this isnt working either.

    =IF(F2<100, 0, IF(F2>=100 AND <110, (((E2-D2)*0.1)+666), IF(F2>=110 AND <120, (((E2-D2)*0.2)+666), (((E2-D2)*0.3)+666))))

  4. #4
    Registered User
    Join Date
    06-28-2012
    Location
    Glasgow
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Whats wrong with my code

    thanks martin -

    I dont understand how I would write that?

  5. #5
    Forum Expert ben_hensel's Avatar
    Join Date
    01-26-2012
    Location
    Northeast USA
    MS-Off Ver
    Office 365
    Posts
    2,043

    Re: Whats wrong with my code

    Quote Originally Posted by OP
    what's wrong with my code
    >>it doesn't work.

    glad I could help

    I love easy questions

    ...

    More seriously, though, you're using AND wrong.

    Please Login or Register  to view this content.
    should be

    Please Login or Register  to view this content.
    Anyway, aside from that,

    I'm not sure you've set up your value handing correctly, which is a problem with the way you've designed it, not with the syntax.

  6. #6
    Registered User
    Join Date
    06-28-2012
    Location
    Glasgow
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Whats wrong with my code

    ok - this?

    =IF(F2<100, 0, IF(AND(F2>=100, <110), (((E2-D2)*0.1)+666)), IF(AND(F2>=110, <120),(((E2-D2)*0.2)+666),(((E2-D2)*0.3)+666)))

  7. #7
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Whats wrong with my code

    you dont need "and" at all as each condition is checked in turn
    =IF(F2<100,0,IF(F2<110,(E2-D2)*0.1+666,IF(F2<120,(E2-D2)*0.2+666,(E2-D2)*0.3+666)))
    but it can be written like this
    =IF(F2=0,0,(E2-D2)*LOOKUP(F2,{100,110,120},{0.1,0.2,0.3})+666)

  8. #8
    Registered User
    Join Date
    06-28-2012
    Location
    Glasgow
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Whats wrong with my code

    =IF(F2<100, 0, IF(AND(F2>=100, f2<110), (((E2-D2)*0.1)+666)), IF(AND(F2>=110, f2<120), (((E2-D2)*0.2)+666)), (((E2-D2)*0.3)+666))

    I think this might be legit - but excel is telling me I have too many arguments...?

    god im useless at this.

  9. #9
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Whats wrong with my code

    ok read posts that have been posted before please.i gave you 2 solutions but if you really wanted to construct it the way you are trying
    =IF(F2<100,0,IF(AND(F2>=100,F2<110),(E2-D2)*0.1+666,IF(AND(F2>=110,F2<120),(E2-D2)*0.2+666,(E2-D2)*0.3+666)))
    but as i said above you dont need AND
    and FYI dont go mad with () (((E2-D2)*0.1)+666)) is simply (e2-d2)*0.1+666 the operators take precedence in this order everything inside brackets is calculated first,then division then multiplication then addition/subtraction
    so 2*3+8 =6+8=14 no need to(2*3)+8 or 8+2*3 is the same 8+6=14
    Last edited by martindwilson; 06-28-2012 at 12:26 PM.

  10. #10
    Forum Expert ben_hensel's Avatar
    Join Date
    01-26-2012
    Location
    Northeast USA
    MS-Off Ver
    Office 365
    Posts
    2,043

    Re: Whats wrong with my code

    One too many right paren after both the first "+666" bits; it was terminating the relevant IF loop early so the first IF loop was thinking you were giving it like five terms, like so: IF(1,2,3,4,5) which made excel freak out.

    Try this:

    Please Login or Register  to view this content.
    But yeah martin's formulations are more elegant and easier to read.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1