+ Reply to Thread
Results 1 to 11 of 11

VBA to find exact value amongst "Indentical" values

  1. #1
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    VBA to find exact value amongst "Indentical" values

    Hi,

    What VBA code can be used to find the exact value amongst other identical values but unique values.

    I have attached a simple column of data to explain example.

    Thanks
    Attached Files Attached Files
    Last edited by Foreverlearning; 04-01-2012 at 03:23 AM.

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: VBA to find exact value amongst "Indentical" values

    Hi Forever,

    Well, to be technical, there's no such thing as identical but unique unless you only have one value and consider it identical to itself. As for your issue of finding a value in a list and displaying its address, you could try:
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: VBA to find exact value amongst "Indentical" values

    Forever

    Your question and indeed what you had written in your attached file implies that you have tried something already - I think it would help to post what you have tried so that we can point out why it might not be working.

  4. #4
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: VBA to find exact value amongst "Indentical" values

    When I use the Find statement it always finds the first part of the value which is the same as others but not completly.

    Example:
    0234-wrt-rty
    0234-wrt-rty-wer
    0234-wrt-rty-wee

    If I am looking for 0234-wrt-rty-wee it finds 0234-wrt-rty 1st
    This is using a textbox as
    Please Login or Register  to view this content.
    .find(me.txtBox.value)
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: VBA to find exact value amongst "Indentical" values

    What is the value in Me.TxtBox.Value?

  6. #6
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: VBA to find exact value amongst "Indentical" values

    The Value is 0234-wrt-rty-wer
    or when there is a space in between

    eg:
    0234 wrt rty wer that is if the data had no "-" between them

  7. #7
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: VBA to find exact value amongst "Indentical" values

    That should work - any chance you can attach a workbook with the sample data and texbox? Include the textbox value that doesn't work (eg in a spare cell) and indicate how the code was being executed.

  8. #8
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: VBA to find exact value amongst "Indentical" values

    Hi,
    I have attached an example

    When you select to find 1st 2 examples they are correct but when you select
    to find just jam it finds the value before it

    How do you find exact value in combo box

    Thanks
    Attached Files Attached Files

  9. #9
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: VBA to find exact value amongst "Indentical" values

    This is an absolutly blind guess, but if you are using the .Find method, the LookAt argument should be set to xlWhole.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  10. #10
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: VBA to find exact value amongst "Indentical" values

    Thanks Mike.

    So you are saying that we must use xlwhole to find correct value otherwise it finds 1st value part

  11. #11
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: VBA to find exact value amongst "Indentical" values

    Thanks Mike.

    So you are saying that we must use xlwhole to find correct value otherwise it finds 1st value part.

    The correct way to add to this code

    Please Login or Register  to view this content.
    would be? I mean how would you code to find...

    Thanks
    Last edited by Foreverlearning; 04-01-2012 at 01:04 AM.

  12. #12
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: VBA to find exact value amongst "Indentical" values

    That would be:

    Please Login or Register  to view this content.
    Note that what you said in post #4 would not be solved by this - but I suspect you didn't actually have these criteria failing. In your workbook, "jam" is part of all the values, so if you don't specify the match to be on the entire cell value (i.e. xlWhole) and it is rather set to xlPart then the "jam" will match against any part of the cell value (in this case the first 3 characters).

    Find's argument settings persist between function calls, so it is always best to be completely explicit every time you use it in code (ie always give a value to the optional arguments). This can make your code longer, but at least you guarantee it should behave how you mean it to.

  13. #13
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: VBA to find exact value amongst "Indentical" values

    Thanks Firefly & Mike

    That explains the issue. Learn something all the time

+ 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