+ Reply to Thread
Results 1 to 10 of 10

Worksheet.Find - A way to Find a STRING with an unknown group of numbers within a cell

  1. #1
    Registered User
    Join Date
    07-19-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2007
    Posts
    11

    Worksheet.Find - A way to Find a STRING with an unknown group of numbers within a cell

    I using this method to find a text string within a selected cell. The string may or may not exist and I have further error handling for those instances.

    WorksheetFunction.Find("This is a test string", Selection.Value)

    What I'd like to do is find that text string followed by an unknown group of 6 characters followed by a quotation " mark.

    Note: (the unknown groupl of characters will actually be numbers, but that's not important unless it makes it easier that they are numbers) followed by

    As an example, the selected cell contains the following:

    now is the time for all good men to come to the this is a test123456" of their country

    The "123456" will be the unknown characters (numbers).
    So the code should be searching for "this is a test######" that is followed by a quotation mark.

    I hope this makes sense.

    Thanks.
    Paul

  2. #2
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: Worksheet.Find - A way to Find a STRING with an unknown group of numbers within a cell

    view results in intermediate window
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    07-19-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Worksheet.Find - A way to Find a STRING with an unknown group of numbers within a cell

    Thank you for this suggestion. I think I can make this work... Of course I would replace the quoted item in the "lngstr =" line to "selection.value" based on a little testing I've done with your suggestion so far. Seems to work.

    This is really good.

    Thanks again,
    Paul

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,950

    Re: Worksheet.Find - A way to Find a STRING with an unknown group of numbers within a cell

    You cannot use wildcards in the Find function, but you can in the Search function
    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,486

    Re: Worksheet.Find - A way to Find a STRING with an unknown group of numbers within a cell

    Here is a UDF (user defined function) that you can use...
    Please Login or Register  to view this content.
    Simply pass it the text to search in (either a cell reference or a quoted text string) and the base text (the part without the numbers) (again either as a cell reference or a quoted text string) and the function will return the base text along with the trailing six digits.

  6. #6
    Registered User
    Join Date
    07-19-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Worksheet.Find - A way to Find a STRING with an unknown group of numbers within a cell

    This is really good. I think this is what I'm looking for. My initial test is looking positive so far using a simple sample cell string. I was having trouble when there were multiple matching items in the same cell. Once I find the matching criteria, I'm adding a specified string before the quotation at the end. This means the next time I run the code, that should no longer be a match. However, if there was a second match in the same cell, then that should now be identified. I'm going to give this a go.

    Thanks again.
    Paul

  7. #7
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,486

    Re: Worksheet.Find - A way to Find a STRING with an unknown group of numbers within a cell

    Not sure who's message you were responding to (when more than one person has offered help, you should mention the name of who you are responding to in your message). I have modified my UDF to return all of the text strings that start with your "find me" text followed by six and only six digits. The list is comma/space delimited if there is more than one instance in the "search me" text. Note that I used the same function name so you have to remove my first UDF from your project so that VBA can find the following one.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    07-19-2010
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Worksheet.Find - A way to Find a STRING with an unknown group of numbers within a cell

    Sorry Rick. My reply was to Fluff13. I was able to apply that suggestion to my code and seems to work well. I didn't get a chance to try out your UDF. However, I know you from many years of Excel contribution going back to the News Group days. Great help to many in the past and you continue. In any case, thank you for your suggested solution. I may still try to look into your solution and apply the methods in other code.

    Thanks again.
    Paul

  9. #9
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,950

    Re: Worksheet.Find - A way to Find a STRING with an unknown group of numbers within a cell

    Glad to help & thanks for the feedback.

  10. #10
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,486

    Re: Worksheet.Find - A way to Find a STRING with an unknown group of numbers within a cell

    Given you want to be able to identify multiple occurrences of your base "find me" text (that portion without the 6 digits), you may find the code I posted in Message #7 to be of use (it finds and reports back all such occurrences without you having to do anything special). Of course, you may not want the result all within one cell which would mean my function would not help you out. Anyway, you may want to try the code out just to see.
    Last edited by Rick Rothstein; 10-16-2020 at 04:24 PM.

+ 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] Formula to Find a Match of String of Numbers in a Larger String of Numbers
    By MattAquino in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 08-16-2019, 12:30 PM
  2. How to use IF & FIND to find out diferent string in cell
    By ericyipcw in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-12-2017, 10:40 AM
  3. [SOLVED] Can I use FIND function to find specific string in a single cell?
    By bonpara in forum Excel General
    Replies: 2
    Last Post: 10-05-2015, 05:46 PM
  4. Need help find longest group of numbers
    By VBisgreat in forum Excel Programming / VBA / Macros
    Replies: 36
    Last Post: 03-22-2013, 03:52 PM
  5. Group Numbers and find average
    By aheye in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-17-2012, 10:15 AM
  6. how to find a STRING in a worksheet and select the cell containing it.
    By excelkeechak in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-28-2009, 07:27 AM
  7. Replies: 1
    Last Post: 01-09-2006, 09:30 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