+ Reply to Thread
Results 1 to 6 of 6

Vlookup #N/A using VBA

  1. #1
    Registered User
    Join Date
    11-07-2017
    Location
    India
    MS-Off Ver
    Microsoft Office Standard 2013
    Posts
    6

    Vlookup #N/A using VBA

    Is there any way that I can get #N/A using vlookup code in VBA if the corresponding value is not available?
    It just gives errors when the value is not found.

    On using On Error Resume Next , the error is resolved however, still after trying many ways I am unable to print #N/A.
    Kindly help

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Vlookup #N/A using VBA

    Post your existing code.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Vlookup #N/A using VBA

    Hi,

    If you use Application.Vlookup instead of WorksheetFunction.Vlookup, it will return an error value if the lookup value is not found, rather than causing a run time error. You can store the result in a Variant variable and test it using IsError.
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  4. #4
    Registered User
    Join Date
    11-07-2017
    Location
    India
    MS-Off Ver
    Microsoft Office Standard 2013
    Posts
    6

    Re: Vlookup #N/A using VBA

    On Error Resume Next

    For i = 2 To 100

    Objectm= sheet1.Cells(i, "C").Value
    Rangem = sheet2.Range("C:I")

    Value1 = Application.WorksheetFunction.VLookup(Objectm, Rangem, 7, False)

    If IsError(Value1) Then

    Sheet1.Cells(i, "H") = "#N/A"

    Else

    Sheet1.Cells(i, "H") = Value1

    End If

    Next

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Vlookup #N/A using VBA

    Please use code tags when posting code.

    Note that that is not what I suggested, which was to use Application.Vlookup and not WorksheetFunction.Vlookup. Additionally, since you actually want the error value in there, you can use less code
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-09-2016
    Location
    Perth
    MS-Off Ver
    2010
    Posts
    8

    Re: Vlookup #N/A using VBA

    Please Login or Register  to view this content.

+ 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. [SOLVED] When vlookup ragnes is mutiple: How do vlookup value finding occurrence against coresspond
    By silambarasan.J in forum Excel Formulas & Functions
    Replies: 34
    Last Post: 07-07-2015, 09:32 AM
  3. Replies: 0
    Last Post: 12-26-2013, 01:12 PM
  4. 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
  5. how to bring all vlookup returns even with duplicate vlookup search keys
    By NYC4LIFE in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-06-2013, 04:53 PM
  6. 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
  7. Replies: 5
    Last Post: 07-29-2009, 07:53 AM

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