+ Reply to Thread
Results 1 to 6 of 6

shorten an if statement

Hybrid View

  1. #1
    Registered User
    Join Date
    04-19-2009
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    21

    shorten an if statement

    How can I shorten this If statement?

    =IF(E6="Monday",J7,IF(E6="Tuesday",K7,IF(E6="Wednesday",L7, IF(E6="Thursday",M7,IF(E6="Friday",N7,IF(E6="Saturday",O7, IF(E6="Sunday",P7)))))))

    This works for me but I was wondering if there was an easier way to do write this formula.
    Last edited by sable; 08-24-2009 at 02:48 PM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: shorten an if statement

    One Way:

    =CHOOSE(WEEKDAY(E6,2),J7,K7,L7,M7,N7,O7,P7)

    assuming you have an actual date in E6, formatting as "dddd"


    else, you can list the days in J6:P6 and use HLookup

    e.g.

    =Hlookup(E6,J6:K7,2,0)

    or if you want to put days lower down, say in J100:P100

    =Index(J7:P7,Match(E6,J100:P100,0))
    Last edited by NBVC; 08-24-2009 at 02:42 PM.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    04-19-2009
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    21

    Re: shorten an if statement

    actually the first way worked perfectly! Thanks so much!

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,762

    Re: shorten an if statement

    Perhaps also......

    =INDEX(J7:P7,WEEKDAY(E6,2))

    and note that if E6 is blank both that formula and NBVC's CHOOSE will return the (Saturday) value in O7 so you might need to add an IF, i.e.

    =IF(E6="","",INDEX(J7:P7,WEEKDAY(E6,2)))
    Last edited by daddylonglegs; 08-24-2009 at 03:10 PM.

  5. #5
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: shorten an if statement

    Quote Originally Posted by daddylonglegs View Post
    Perhaps also......

    =INDEX(J7:P7,WEEKDAY(E6,2))
    Good one... should've thought of that.. was fixed on a way trying to use Lookup() but can't use cell refs in arrays within formula.....and the Index() passed me by.

  6. #6
    Registered User
    Join Date
    04-19-2009
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    21

    Re: shorten an if statement

    thanks daddylonglegs... that actually a little better for me.

+ 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