+ Reply to Thread
Results 1 to 11 of 11

VLookup in VBA

  1. #1
    Registered User
    Join Date
    11-10-2010
    Location
    Cape Town, South Africa
    MS-Off Ver
    M365 2209
    Posts
    22

    VLookup in VBA

    In my workbook, I have a worksheet named ITEMS and another named PLANTS. I am trying to get an answer in ITEMS Cell O12, accessing a reference code in ITEMS Cell O12, and using that reference to look up a value in the second column of a vertical table in PLANTS. The syntax I have used is as follows :

    Sheets("ITEMS").Range("O12") = Application. WorksheetFunction. VLookup(Sheets("ITEMS").Range("AD6"),Sheets("PLANTS").Range("B3:F65"), 2,FALSE)

    I have looked up the use of the Vlookup function in VBA and the above appears to be correct, but I get an error 1004.

    Can anyone find a way round that error?

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,523

    Re: VLookup in VBA

    Hi jackson7249,

    I'd say there's no exact match for what's in cell AD6 of the ITEMS tab within the range B3:F65 of the PLANTS tab.

    Here's two alternatives (I personally like the Evaluate method):

    Please Login or Register  to view this content.
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Registered User
    Join Date
    11-10-2010
    Location
    Cape Town, South Africa
    MS-Off Ver
    M365 2209
    Posts
    22

    Re: VLookup in VBA

    Hi Robert,

    Thanks so much for your reply.

    Unfortunately I couldn't get the routines to work.

    Would it help if I attached the workbook so that you could see where my error/s are ?

    Regards,

    Robin

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,523

    Re: VLookup in VBA

    Would it help if I attached the workbook so that you could see where my error/s are
    Yes that would be great.

  5. #5
    Registered User
    Join Date
    11-10-2010
    Location
    Cape Town, South Africa
    MS-Off Ver
    M365 2209
    Posts
    22

    Re: VLookup in VBA

    Here is the workbook.

    Regards,

    Robin
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,523

    Re: VLookup in VBA

    Hi Robin,

    This should do it:

    Please Login or Register  to view this content.
    Regards,

    Robert

  7. #7
    Registered User
    Join Date
    11-10-2010
    Location
    Cape Town, South Africa
    MS-Off Ver
    M365 2209
    Posts
    22

    Re: VLookup in VBA

    Thanks Robert.

    I changed the option but it didn't make any difference.

    Did you try?

    Regards,

    Robin

  8. #8
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,523

    Re: VLookup in VBA

    Did you try?
    Of course

    Run the Find1 macro on the attached to see the result in cell O12 of the ITEMS tab.

    Thanks,

    Robert
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    11-10-2010
    Location
    Cape Town, South Africa
    MS-Off Ver
    M365 2209
    Posts
    22

    Re: VLookup in VBA

    Sorry Robert,

    Thanks so much for the help.

    It is really appreciated.

    Kind regards,

    Robin

  10. #10
    Registered User
    Join Date
    11-10-2010
    Location
    Cape Town, South Africa
    MS-Off Ver
    M365 2209
    Posts
    22

    Re: VLookup in VBA

    Hi Robert,

    Me again. I had to edit your subroutine so that I could use it in two different routines but it no longer works.

    What did I do wrong?


    Option Explicit
    Sub Find1()
    Sheets("START").Select
    If Range("AD6") = 1 Then GoTo Newprice
    Sheets("ITEMS").Range("O12").Value = Evaluate(IFERROR(VLOOKUP(" & Sheets("ITEMS").Range("AD6").Value & ",PLANTS!$B$3:$F$65,5,FALSE),0)")
    GoTo Finish
    Newprice:
    Sheets("ITEMS").Range("E23").Value = Evaluate(IFERROR(VLLOKUP(" & Sheets("ITEMS").Range("AD6").Value & ",CHOSEN!$B$3:$I$90,8,FALSE),0)")
    Finish:
    Kind regards,

    Robin

    Robin
    Attached Files Attached Files

  11. #11
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VLookup in VBA

    You forgot the double quotes in front of IFERROR & typo in second VLOOKUP.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

+ 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: 5
    Last Post: 12-07-2016, 09:18 AM
  2. Replies: 0
    Last Post: 12-26-2013, 01:12 PM
  3. Display Cell within VLookup range that excel thinks matches the VLookup Value
    By headachexcelperson in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-04-2013, 04:56 PM
  4. [SOLVED] Vlookup is not working and giving =vlookup(B2,$T$2:$U$135,2,false) this kind of values.
    By yogeshsharma1981 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-09-2013, 04:08 PM
  5. vlookup? match? index? MULTIPLE criteria for vlookup search problem....
    By aborg88 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-11-2013, 09:56 AM
  6. Replies: 5
    Last Post: 07-29-2009, 07:53 AM
  7. [SOLVED] vlookup function-Can vlookup command find the data from the 5 sheets.
    By Rishab shah in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM

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