+ Reply to Thread
Results 1 to 7 of 7

IF/THEN Syntax issues

  1. #1
    Registered User
    Join Date
    06-12-2012
    Location
    New Hampshire
    MS-Off Ver
    Excel 2003
    Posts
    2

    IF/THEN Syntax issues

    Hi all!

    First time poster here. I'm having trouble figuring out how to write an IF/THEN statement to auto-populate a column for me.

    I need cell H2 to check cell A2 and based on what it finds in A2, it needs to spit out one of four variables.

    For Example:

    If A2 is between 10-15, H2 = 1, If A2 is between 20-25, H2 = 2, If A2 is between 30-35, H2 = 3, If A2 is any other number outside of these ranges, H2 needs to be blank.

    Thanks!

    Ed

  2. #2
    Registered User
    Join Date
    08-14-2010
    Location
    Halifax, Nova Scotia, Canada
    MS-Off Ver
    Excel 2007, Excel 2000
    Posts
    1

    Re: IF/THEN Syntax issues

    You could use the following, but if you cannot have more than 7 if statements nested.

    =IF(AND(A2>=10,A2<=15),1,IF(A2>=20,A2<=25),2,IF(AND(A2>=30,A2<=35),3,"")))

    If you have more than 7, you will need to implement a lookup table.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,494

    Re: IF/THEN Syntax issues

    One way, with the information provided:

    =IF(AND(A2>=10,A2<=15),1,IF(AND(A2>=20,A2<=25),2,IF(AND(A2>=30,A2<=35),3,"")))


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: IF/THEN Syntax issues

    EdinNH,

    Welcome to the Excel Forum.

    In cell H2 try:
    =LOOKUP(A2,{0,10,16,20,26,30,36},{"",1,"",2,"",3,""})
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  5. #5
    Registered User
    Join Date
    06-12-2012
    Location
    New Hampshire
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: IF/THEN Syntax issues

    Works like a charm! Thanks guys!

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,494

    Re: IF/THEN Syntax issues

    You're welcome. Thanks for the rep.

    The LOOKUP approach is neat and scalable, while the IF/AND combination is limited.

    Regards, TMS

  7. #7
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: IF/THEN Syntax issues

    EdinNH,

    Thanks for the feedback.

    You are very welcome. Glad we could help.

    Come back anytime.

+ 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