+ Reply to Thread
Results 1 to 4 of 4

Application vlookup is not returning value correctly

Hybrid View

reachharry Application vlookup is not... 02-18-2020, 11:23 AM
AliGW Re: Application vlookup is... 02-18-2020, 11:26 AM
Pepe Le Mokko Re: Application vlookup is... 02-18-2020, 11:26 AM
reachharry Re: Application vlookup is... 02-18-2020, 09:48 PM
  1. #1
    Registered User
    Join Date
    05-25-2012
    Location
    Chennai,TamilNadu,India
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    61

    Application vlookup is not returning value correctly

    Hi,

    I am trying to use application,vlookup to extract the related data based on the user provided code number. Even though the code number is existing in the array, it is not giving the proper result. I have given my code below, any help is much appreciated.

    Function test(usercode As String) As Long
    'declaring an array
    Dim arr As Variant

    'assigning range of values to the array
    arr = Worksheets(1).Range("A1").CurrentRegion

    'using a vlookup formula to take the related data of the code from the array
    If IsError(Application.VLookup(usercode, arr, 2, 0)) Then
    test = 0
    Else
    test = Application.VLookup(usercode, arr, 2, 0)
    End If

    End Function

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,302

    Re: Application vlookup is not returning value correctly

    Administrative Note:

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2504
    Posts
    13,640

    Re: Application vlookup is not returning value correctly

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)

  4. #4
    Registered User
    Join Date
    05-25-2012
    Location
    Chennai,TamilNadu,India
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    61

    Re: Application vlookup is not returning value correctly

    Sorry for not adapting to the forum rules..now i have placed my code under the code tag

    here is my query:
    I am trying to use application,vlookup to extract the related data based on the user provided code number. Even though the code number is existing in the array, it is not giving the proper result. I have given my code below, any help is much appreciated.

    Function test(usercode As String) As Long
    'declaring an array
    Dim arr As Variant
    
    'assigning range of values to the array
    arr = Worksheets(1).Range("A1").CurrentRegion
    
    'using a vlookup formula to take the related data of the code from the array
    If IsError(Application.VLookup(usercode, arr, 2, 0)) Then
    test = 0
    Else
    test = Application.VLookup(usercode, arr, 2, 0)
    End If
    End Function

+ 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. [SOLVED] IF function not returning values correctly (what did I miss)
    By Dan_B in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-09-2019, 09:40 AM
  2. Application.EnableEvents not workng correctly code too long? not written correctly?
    By Carissaleigh2010 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-22-2019, 01:13 PM
  3. Outlook VBA - Application.quit will not work correctly.
    By Rchie in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-28-2015, 11:12 AM
  4. Issue with formula not returning data correctly
    By cdwbxr in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-08-2014, 07:40 AM
  5. [SOLVED] Showing Degrees correctly in cells for aviation application
    By Macgos in forum Excel General
    Replies: 2
    Last Post: 04-05-2012, 07:28 AM
  6. Application.Statusbar not updating correctly
    By tryer in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-08-2011, 03:13 AM
  7. Function not returning correctly please look
    By AA76 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-27-2006, 04:45 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