+ Reply to Thread
Results 1 to 11 of 11

vb vlookup using 2 columns

  1. #1
    Registered User
    Join Date
    01-27-2012
    Location
    Durham
    MS-Off Ver
    Excel 2003
    Posts
    61

    vb vlookup using 2 columns

    Hi

    I am trying to do a vlookup using 2 columns i.e first name , last name to return a day

    I have the vb code for looking up the first and second columns, but dont know how to use them together to return the third column.

    An example is below:

    a b c
    1 adam smith Monday
    2 adam jones Tuesday
    3 steve smith Wednesday
    4 steve jones Thursday

    Id like to lookup columns A and B to return C. I wont post my code incase I need something completely different!

    Thanks in advance
    Last edited by cooket4; 02-07-2012 at 12:49 PM.

  2. #2
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: vb vlookup using 2 columns

    You could use an array formula
    Please Login or Register  to view this content.
    This would place the formula into A8 to find the value in colulmn D when matching Adam (Column B) and Smith (Column C)

    Hope this helps.
    Anthony
    “Confidence never comes from having all the answers; it comes from being open to all the questions.”
    PS: Remember to mark your questions as Solved once you are satisfied and rate the answer(s) questions.”

  3. #3
    Registered User
    Join Date
    01-27-2012
    Location
    Durham
    MS-Off Ver
    Excel 2003
    Posts
    61

    Re: vb vlookup using 2 columns

    Thanks for the reply

    I have got it to work in excel, but I have tried to adapt it to my vb userform

    using the same example data - on sheet "Rota"

    a b c
    1 adam smith Monday
    2 adam jones Tuesday
    3 steve smith Wednesday
    4 steve jones Thursday

    Please Login or Register  to view this content.
    I get an error sayng the argument "match" is not optional.

    Thanks
    Last edited by cooket4; 02-03-2012 at 10:45 AM.

  4. #4
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: vb vlookup using 2 columns

    I just cannot get the formulas to work in VBA - here is a set of non array formulas that will do the same
    =INDEX(C1:C4,MATCH(1,INDEX((A1:A4="adam")*(B1:B4="jones"),0,1),0))
    =INDEX(C1:C5,SUMPRODUCT((A1:A5="adam")*(B1:B5="jones")*ROW(B1:B5)))
    One option would be to write the value to the spreadsheet using the following then read it back into the textbox
    Please Login or Register  to view this content.
    or use a lot more code using FIND to get the answer
    Please Login or Register  to view this content.
    Hope this helps.
    Anthony
    “Confidence never comes from having all the answers; it comes from being open to all the questions.”
    PS: Remember to mark your questions as Solved once you are satisfied and rate the answer(s) questions.”
    Last edited by smuzoen; 02-04-2012 at 08:36 AM.

  5. #5
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: vb vlookup using 2 columns

    Hi Guys,

    Try this. I have used Column G as demostration. Maybe you can adjust to suit. If any day is left out, the word "Empty" will show in that specific row:

    Copy this Code to a Module, and test it.

    Please Login or Register  to view this content.
    Hope it helps!
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  6. #6
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: vb vlookup using 2 columns

    This was doing my head in - the following should work
    Please Login or Register  to view this content.
    Since I did not set up comboboxes you should just have to try
    Please Login or Register  to view this content.
    I assume Cmb_First_Name and Cmb_Last_Name are comboboxes?

    Let me know how you get on
    Last edited by smuzoen; 02-04-2012 at 08:58 AM.
    Hope this helps.
    Anthony
    Pack my box with five dozen liquor jugs
    PS: Remember to mark your questions as Solved once you are satisfied. Please rate the answer(s) by selecting the Star in the lower left next to the Triangle. It is appreciated?

  7. #7
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: vb vlookup using 2 columns

    Hello cooket4,

    May I suggest you upload a sample Workbook of what you have, and an explanation as to what exactly you want. Doing so will help us to focus on the actual issue, without assuming any possible solutions which may be way off track.

    @smuzoen,

    Re:

    Cmb_Last_Name = "Jones": Cmb_First_Name = "Adam"
    How would that help if the names are "Zabor" and "Charlie" ?

    Just wondering...

  8. #8
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: vb vlookup using 2 columns

    @ Winon
    That is what error handling and code is for - he asked how to incorporate the Comboboxes (I assume) into a formula with worksheet functions which I supplied. He said he was using a userform so obviously the variables are controls
    Please Login or Register  to view this content.
    I had already posted an answer along the lines of your suggestion
    Please Login or Register  to view this content.
    The point was how to incorporate userform controls into the formula.
    Last edited by smuzoen; 02-04-2012 at 01:40 PM.

  9. #9
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: vb vlookup using 2 columns

    @ smuzoen,


    Re:
    Please Login or Register  to view this content.
    Thanks for responding. I do know about ErrorHandling, and this pretty much completes your Code, without leaving cooket4 wondering what is happening if nothing was found.

    I also believe that you may be very close with what you are assuming cooket4 wants.

    Hope you get a good Rep for your efforts!

    @ cooket4,

    It would be appreciated if you could confirm if your problem was resolved.
    Last edited by Winon; 02-05-2012 at 03:59 AM. Reason: remove signature

  10. #10
    Registered User
    Join Date
    01-27-2012
    Location
    Durham
    MS-Off Ver
    Excel 2003
    Posts
    61

    Re: vb vlookup using 2 columns

    Hi all

    Thanks for the suggestiions. I will be trying these out today or if not tomorrow. I will let you know when I get it working

    Thanks again

  11. #11
    Registered User
    Join Date
    01-27-2012
    Location
    Durham
    MS-Off Ver
    Excel 2003
    Posts
    61

    Re: vb vlookup using 2 columns

    Hi

    I have used Smuzoen's 'alot more code' FIND. It works like a charm!

    Thank you

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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