+ Reply to Thread
Results 1 to 11 of 11

Loop + vLookup cause formula too long

  1. #1
    Registered User
    Join Date
    11-06-2007
    Posts
    8

    Loop + vLookup cause formula too long

    Dear All,

    I really need help, thanks in advance first.

    Following is part of my formula ( still have more):

    =IF(C4="A",VLOOKUP(A4,'Emp List'!A:B,2,0),"")&IF(C4="B",VLOOKUP(A4,'Emp List'!A:C,3,0),"")&IF(C4="C",VLOOKUP(A4,'Emp List'!A:D,4,0),"")&IF(C4="D",VLOOKUP(A4,'Emp List'!A:E,5,0),"")&IF(C4="E",VLOOKUP(A4,'Emp List'!A:F,6,0),"")&IF(C4="F",VLOOKUP(A4,'Emp List'!A:G,7,0),"")&IF(C4="G",VLOOKUP(A4,'Emp List'!A:H,8,0),"")&IF(C4="H",VLOOKUP(A4,'Emp List'!A:I,9,0),"")&IF(C4="I",VLOOKUP(A4,'Emp List'!A:J,10,0),"")&IF(C4="J",VLOOKUP(A4,'Emp List'!A:K,11,0),"")&IF(C4="K",VLOOKUP(A4,'Emp List'!A:L,12,0),"")&IF(C4="L",VLOOKUP(A4,'Emp List'!A:M,13,0),"")&IF(C4="M",VLOOKUP(A4,'Emp List'!A:N,14,0),"")&IF(C4="N",VLOOKUP(A4,'Emp List'!A:O,15,0),"")&IF(C4="O",VLOOKUP(A4,'Emp List'!A:P,16,0),"")&IF(C4="P",VLOOKUP(A4,'Emp List'!A:Q,17,0),"")&IF(C4="Q",VLOOKUP(A4,'Emp List'!A:R,18,0),"")&IF(C4="R",VLOOKUP(A4,'Emp List'!A:S,19,0),"")

    I tried nested condition, but only can up to 7 levels, hence i try this formula but cause my formula too long.

    Is there a way to shorten it?

    The working is C4 is the drop down list, and If C4 = a, then will use A vlookup formula, if C4 is B , then will use B vlookup formula and etc.

    Pls try to help`~

    Many Many Many Tks

    Asyura

  2. #2
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Hi, Asyura. Try this much shorter version of the formula:
    Please Login or Register  to view this content.
    HTH

    Jason

  3. #3
    Registered User
    Join Date
    11-06-2007
    Posts
    8
    Thanks Jason..

    Actually i'm quite new to Excel.. doesn't know much about indirect..

    Appreaciate you can explain to me ,the working for that formula..

    My C4 not exactly is Alphablet.
    C4 can be Surame,Given Name, ID, and etc.
    A, B, C and etc just the example of drop down list

    BTW, Many Many tks =)
    Last edited by asyuradou; 11-07-2007 at 03:37 AM.

  4. #4
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Is the content of cell A4 the column headings of 'Emp List'?

  5. #5
    Registered User
    Join Date
    11-06-2007
    Posts
    8
    Yes.

    If i key in the staff id in A4, it will do the vlookup to Emp List.

    If A4 = ABC and C4 = Surname,
    It will vlookup A4 = ABC and display the surname.

    If A4 = ABC and C4 = Given Name
    It will vlookup A4 = ABC and display the Given Name

  6. #6
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Ok, try this one. Before, I was using your example of A, B, C, etc. to denote the columns. Since you have data in here that matches the column headings, you can use MATCH to determine the column number. So try this one, and let me know how it works:
    Please Login or Register  to view this content.
    HTH

    Jason

  7. #7
    Registered User
    Join Date
    11-06-2007
    Posts
    8
    Yes Yes..

    Jason, it's workable... Many Many Tks.

    But i have another problem again. =p

    Same Logic but instead of using vlookup, i need to define the drop down list.

    For example if C4 = "Gender", E4 is a drop down list with value {Male, Female}
    If C4 = "Marital Status", E4 is a drop down list with Value {Single, Married, Divorced} and etc.

    My working is, i define a name for Male and Female as Gender.
    After that i use validation and create a list with source = Gender.

    So the condition is gonna set at Source.
    But If.. Else condition only can up to 7 level.
    Hence, i switch to concantenate or "&" method, but seem it prompt me the error msg that, "Source have error"

    If there a way to define such a way or i should use macro?

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    No need for INDIRECT or IF.

    =VLOOKUP(A4,'Emp List'!A:B,CODE(C4)-CODE("A")+2,0)

  9. #9
    Registered User
    Join Date
    11-06-2007
    Posts
    8
    Thanks Norie, but seem it's not workable for my spreadsheet.

    Now my another problem is the validation list. How am i going to put the conditions at validation list's source.

  10. #10
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Hi, Asyura.

    See if this link works for you:

    http://www.contextures.com/xlDataVal02.html

    HTH

    Jason

  11. #11
    Registered User
    Join Date
    06-11-2007
    Location
    Nonthaburee Province, Thailand
    MS-Off Ver
    MS Office 2003 to MS Office 2010
    Posts
    82
    Dear Asyura

    If you are Thai people, please read about usaing of Indirect formula at http://www.excelexperttraining.com/f...read.php?t=781
    N. Yauvasuta
    Power User Excel.

+ 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