+ Reply to Thread
Results 1 to 5 of 5

vba: find command, finding exact values

  1. #1
    Registered User
    Join Date
    09-03-2010
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    19

    vba: find command, finding exact values

    I have tried using the vlookup function in VBA, but that has failed to work.
    I am now using the following code instead:

    Please Login or Register  to view this content.

    This returns into textbox2 the value found in the second column of the spreadsheet which corresponds to the value in textbox10. My problem is that the values I have in the 1st column (the column containing the lookup value) are numbers and the code I am using seems to be finding the value which corresponds to the first number which has the number entered in textbox10 nested in it rather than the exact number itself.
    For example, the list of numbers I have in column 1 are
    135
    35
    100
    If the value in textbox10 is 35, the value I get in textbox2 corresponds to the first number in the list containing 35, that is 135, rather than the exact number 35 itself. How can I solve this?

    Thanks!
    Last edited by icylemontea; 09-11-2010 at 02:50 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: vba - vlookup

    1) Be sure to edit your post above and put CODE tags around the code, as per the Forum Rules.

    2) Also, as per forum rules, you should change the title so that it depicts the topic, not something that doesn't work so isn't really part of the topic.

    3) You should always include the parameters LookIn: and LookAt: in your .Find commands. .Find is one of those quirky functions that will use the last LookIn/LookAt parameters from the last time it was used (manually or VBA) and use that setting if you leave it out. Very bad.

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 09-11-2010 at 12:46 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    09-03-2010
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: vba: find command, finding exact values

    Thank you!

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: vba: find command, finding exact values

    Hello ,

    Please use code tags around your code. It makes the code easier to see and copy. Here is an example of how to use VLOOKUP in VBA. It functions a little differently than the worksheet version. In the VBA version you must specify which column of the range you want to search as the VBA version will examine by using the Columns property.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    09-03-2010
    Location
    england
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: vba: find command, finding exact values

    Many Thanks Leith.

+ 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