+ Reply to Thread
Results 1 to 7 of 7

Switch(case) statement(enhanced if statement)

  1. #1
    Registered User
    Join Date
    10-24-2008
    Location
    Bucharest, Romania
    Posts
    5

    Switch(case) statement(enhanced if statement)

    Hello,

    Does MS Excel have an enhanced, multiple choice, IF statement such as those found in most high level programming languages(such as C and Pascal), under names such as case, or switch statements?

    Here is what i need to do: I have to complete a table that containt the name and ID of a data transmission circuit, there is a one to one corespondence between the name and the ID, so I would like the name cell to be completed automatically after i fill in the ID cell.

    One obvious way to do this would be to create the mother of all nested if statements, but this has two problems. First of all, it's a lot of work and I am lazy, and second of all, it scales awfully and should i need to add another circuit, this would need the rethinking of the nested if.

    Obviously, i would be satisfied if anyone could give me another suggestion to solve this problem.

    Thank you,

    Paul

  2. #2
    Forum Expert darkyam's Avatar
    Join Date
    03-05-2008
    Location
    Houston, TX
    MS-Off Ver
    2013
    Posts
    2,191
    Try Vlookup. Syntax is =Vlookup(lookup value,range,column,0 or 1). The 0 is if you want an exact match, which you would in your case, and the 1 finds the closest match without going over.

  3. #3
    Forum Contributor
    Join Date
    04-11-2005
    Location
    London
    Posts
    259
    Yes it does. You would need to write a user defined function in a standard VBA module. You can use a SELECT...CASE construct or IF...ELSEIF...END IF.

    HTH
    Martin
    Martin Short

  4. #4
    Registered User
    Join Date
    10-24-2008
    Location
    Bucharest, Romania
    Posts
    5

    Smile Thanks a lot!

    WOW, you guys sure move fast, the thread is barely half an hour old and already i got two responses.

    Thanks a lot to both, i think i'm going to go with the VLOOKUP solution, because i really don't know how to define my own functions and that seems enough for what I need right now.

    I was heading for the nested if solution(not very elegant but at least it would work), or so i thought, but i found out that at the seventh or eighth nesting level i got an error. I'm pretty sure it wasn't a typo, or any other mistake on my side because i tried rewriting quite a few times.

    Do you by any chance know if there is a limit to how deep this sort of nesting can go, and if it's near the value of 7?

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    In versions of Excel other than 2007, the limit is indeed 7.
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Registered User
    Join Date
    10-24-2008
    Location
    Bucharest, Romania
    Posts
    5

    mea culpa

    Quote Originally Posted by shg View Post
    In versions of Excel other than 2007, the limit is indeed 7.
    yep, i know, i found out for myself. turns out i should have rtfm.

    great forum anyways,

    thanks a million

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    If we didn't answer questions that people could readily find in Help, this would be a quiet forum ...

+ 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