+ Reply to Thread
Results 1 to 8 of 8

How to use a range in an If statement

  1. #1
    Registered User
    Join Date
    08-30-2015
    Location
    Impala
    MS-Off Ver
    10
    Posts
    12

    How to use a range in an If statement

    I am charting when events happen. The time they happen is recorded by the hour it occurred in. For example, if the event happened at 12:30am than the time reference is 0, if it happens at 1:30am the time reference is 1, finishing with a 11:30pm event would get a 23 reference. I want to record the event times in four time periods (AM1 = 0 TO 5, AM2 = 6 TO 11, PM1 = 12 TO 17, AND PM2 = 18 TO 23). Here is the statement I want to make in words:

    If cell A1 is greater than or equal to zero and less than or equal to five, then enter AM1 in cell B2, or if A1 is greater than or equal to 6 and less than or equal to 11, then enter AM2 in cell B2, A1 is greater than or equal to 12 and less than or equal to 17, then enter PM1 in cell B2, otherwise enter PM2 in B2.

    A1 B2
    2 AM1
    7 AM2
    15 PM1
    20 PM2

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Ipswich, England
    MS-Off Ver
    MS 365 Business (Win 10 - Work) & MS 365 Subscription Insider (Win 10 - Home)
    Posts
    40,667

    Re: How to use a range in an If statement

    This perhaps?

    =LOOKUP(A1,{0,6,12,18,24},{"AM1","AM2","PM1","PM2",""})
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!

    Forum Rules (updated September 2018): please read them here.
    How to use the Power Query code you've been given: help here. More about the Power suite here.
    Don't forget to say "thank you" to those who have helped you in your thread. If you wish, you can also reward them by clicking on their reputation star bottom left.

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Excel 2007
    Posts
    19,575

    Re: How to use a range in an If statement

    Rather than a multiple IF statement, you could use that table (assume it is in X1 to Y4) with a VLOOKUP function, like this:

    =IF(A1<$X$1,"",VLOOKUP(A1,$X$1:$Y$4,2))

    Hope this helps.

    Pete

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Ipswich, England
    MS-Off Ver
    MS 365 Business (Win 10 - Work) & MS 365 Subscription Insider (Win 10 - Home)
    Posts
    40,667

    Re: How to use a range in an If statement

    Pete - that table is the results, not the lookup table, but yes, a lookup table would be the other way to go.

  5. #5
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Excel 2007
    Posts
    19,575

    Re: How to use a range in an If statement

    I didn't look at the table very closely.

    Pete

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Ipswich, England
    MS-Off Ver
    MS 365 Business (Win 10 - Work) & MS 365 Subscription Insider (Win 10 - Home)
    Posts
    40,667

    Re: How to use a range in an If statement

    It nearly caught me out - I'd created a VLOOKUP based on it before spotting the criteria in the line above!!!

  7. #7
    Registered User
    Join Date
    08-30-2015
    Location
    Impala
    MS-Off Ver
    10
    Posts
    12

    Re: How to use a range in an If statement

    Thank you, that worked perfectly.

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Ipswich, England
    MS-Off Ver
    MS 365 Business (Win 10 - Work) & MS 365 Subscription Insider (Win 10 - Home)
    Posts
    40,667

    Re: How to use a range in an If statement

    You're welcome!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 3
    Last Post: 11-05-2016, 06:23 AM
  2. [SOLVED] Add IF Statement formula to cells in varying range and paste to used range
    By Webbers in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-26-2015, 01:28 PM
  3. Replies: 1
    Last Post: 11-07-2014, 01:42 PM
  4. If statement with a range and true/false statement
    By aarleblanc in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-20-2012, 06:34 PM
  5. If statement with a range.
    By Mummra in forum Excel General
    Replies: 3
    Last Post: 10-13-2011, 10:29 AM
  6. IF statement for a range
    By rhudgins in forum Excel General
    Replies: 1
    Last Post: 04-14-2010, 06:55 PM
  7. IF Statement Between a Value Range
    By smperkin in forum Excel General
    Replies: 12
    Last Post: 01-14-2007, 06:44 AM

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