+ Reply to Thread
Results 1 to 6 of 6

VBA script to use exact match on just a predefined list and ignore other context.

  1. #1
    Forum Contributor
    Join Date
    04-28-2016
    Location
    Stavanger, Norway
    MS-Off Ver
    365
    Posts
    142

    VBA script to use exact match on just a predefined list and ignore other context.

    Hi

    So I have a script in VBA (see below), which is able to find different types of soil from a defined table in cells with text (exact match) in a column and paste it elsewhere. For example, in Sheet 2 i have a long list of soil types such as:
    silt, clay, silty clay, gravelly clay etc...

    One of the issues I had was that was that the script would pickup on both silt and silty clay for example if I searched for silty clay as it contains "silt". I got some help to change the script to exact match so if I present silty clay, I only get "silty clay" returned. However, this tweak in the scrip (exact match) has also made the script not be able to idetify cells with additional text in it. Lets say I present this in a cell "slighty silty clay", as it is nolonger an exact match, the script does not recognize it. My question is then, how do I keep the script searching for exact matches BASED on the long list of soil types such as: silt, clay, silty clay, gravelly clay etc... )as previously mentioned and ignore everything else?

    Please Login or Register  to view this content.

    Best regards,

    Marius

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA script to use exact match on just a predefined list and ignore other context.

    This will do a whole word match but still be a partial match within the text. So Silt will not match Silty, but Silty Clay will match Slightly Silty Clay.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    04-28-2016
    Location
    Stavanger, Norway
    MS-Off Ver
    365
    Posts
    142

    Re: VBA script to use exact match on just a predefined list and ignore other context.

    Quote Originally Posted by AlphaFrog View Post
    This will do a whole word match but still be a partial match within the text. So Silt will not match Silty, but Silty Clay will match Slightly Silty Clay.

    Please Login or Register  to view this content.
    Okay cheers, where would I implement it into the script? Sorry I'm a complete novice :P

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA script to use exact match on just a predefined list and ignore other context.

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    04-28-2016
    Location
    Stavanger, Norway
    MS-Off Ver
    365
    Posts
    142

    Re: VBA script to use exact match on just a predefined list and ignore other context.

    Thanks for quick reply.

    When I made your adjustment it listed every single cell with the name "clay" in it (e.g silty clay, gravelly clay, sandy clay etc..) instead of just just returning "clay"

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA script to use exact match on just a predefined list and ignore other context.

    I thought that's what you wanted.


    Alright, try this; When you do a search, you have to choose the type of search you want using the Asterisk as a wildcard:
    • Silt for an exact match
    • *Silt* for any partial match (it would match the word Siltly)
    • * Silt * for an exact word match but partial phrase match (would not match Red Silty Clay but it would match Red Silt Clay)


    Change the same line as before to this...

    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. [SOLVED] VBA script - Modify to find exact match and ignore capitalization
    By mss90 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-05-2018, 04:29 PM
  2. [SOLVED] Match Exact formula and Search list with results
    By newbie4 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-29-2015, 08:20 PM
  3. Compare list for Exact Match
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-04-2013, 01:59 PM
  4. Sort data to match a predefined list order
    By Neil0782 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-12-2012, 08:53 AM
  5. Searching a list and finding the exact match from a sublist
    By Lattaio23 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-03-2012, 11:19 AM
  6. Extracting strings from a column of data that match a predefined list
    By jmurray in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-16-2009, 05:10 AM
  7. Replies: 3
    Last Post: 10-27-2008, 08:32 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