We’d like to remind Forumites to please avoid political debate on the Forum.

This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.

📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!

Help with excel and IF statements

Just trying to build something into a spreadsheet i am working and what i want it to do is if a certain value is a cell say 'A2' the formula i want in a particular cell say 'A10' is if the value in A2 is between 500 & 7500 i want value in A10 to be 36, and if the value is between 7501 and 25000 in A2 i want value in A10 to 54 and so on want this for about 8 different between values.

looked at it so much it is driving me crazy! Can anyone give me the formula to do this please? As only used very simple IF statements with excel before and i am self taught.

Thanks in advance

Comments

  • tru
    tru Posts: 9,138 Forumite
    Part of the Furniture 1,000 Posts Photogenic
    A couple of helpful replies HERE

    :D
    Bulletproof
  • =IF(A2<500,"",IF(A2<=7500,36,IF(A2<=25000,54,IF(A2<=27000,66,IF(A2<=28000,67)))))

    and I've included a couple more ranges. However the formula gets a bit unwieldy with more than 4 or 5 IF statements so consider VLOOKUP instead.

    Edit: corrected formula
  • Stompa
    Stompa Posts: 8,383 Forumite
    Part of the Furniture 1,000 Posts Name Dropper
    You could try using HLOOKUP, something like:

    =HLOOKUP(A2,[0,500,7501,10000;1,36,54,123},2)

    You'll notice that the array part of this:

    [0,500,7501,10000;1,36,54,123}

    is split into two parts by a semicolon, so:

    0,500,7501,10000 and 1,36,54,123

    When the value in A2 is >0 and <=500 (the first pair of values in the first part), it'll return 1 (the first value in the second part).
    When the value in A2 is >500 and <=7501 (the second pair of values in the first part), it'll return 36 (the second value in the second part).
    etc.....

    Just adjust the values in the array to suit your requirements.

    IMPORTANT: Where I've used a left square bracket [ above, you should use a left curly bracket instead (this board won't let me write a left curly bracket for some reason).
    Stompa
  • Stompa
    Stompa Posts: 8,383 Forumite
    Part of the Furniture 1,000 Posts Name Dropper
    [quote=Chippy_MintonHowever_the_formula_gets_a_bit_unwieldy_with_more_than_4_or_5_IF_statements_so_consider_VLOOKUP_instead.[/quote]

    You're right, VLOOKUP would probably be more appropriate than HLOOKUP in this instance, in which case the equivalent of my HLOOKUP version becomes:

    =VLOOKUP(A2,[0,1;500,36;7501,54;10000,123},2)
    Stompa
  • The maximum number of ifs that you can nest is 7, so you may need to go down the lookup table route, which is a better option anyway (especially if the range values are likely to change)
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 352.5K Banking & Borrowing
  • 253.7K Reduce Debt & Boost Income
  • 454.4K Spending & Discounts
  • 245.5K Work, Benefits & Business
  • 601.4K Mortgages, Homes & Bills
  • 177.6K Life & Family
  • 259.4K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16K Discuss & Feedback
  • 37.7K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.