+ Reply to Thread
Results 1 to 13 of 13

searching in a string for text cleanly

  1. #1
    Registered User
    Join Date
    08-12-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    24

    searching in a string for text cleanly

    I need to find the row of a sheet that contains a specific text within a text string.
    But the problem comes in the construct of the text string.
    I have a number of rows, each having a reference column 'M' In the rows of column 'M' are a number of text strings:
    "R17, R50, R109, R111"
    "C2, C12, C14"
    "C1, C3, C5, C15"
    for example.
    My problem is trying to find C1. If I use find or INSTR on "C1" I could get the row for "C12", If I search for "C1," then I can get the correct row, but only if C1 is in a list with other numbers after it. If it is the only entry on that row "C1" the search will fail.
    How can I search for a text C1 without pulling up C11 but doesn't fail on a string like "C2, C3, C1"
    Can anyone help with a clean way to search these strings?

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: searching in a string for text cleanly

    One way.
    Select he range first.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-12-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: searching in a string for text cleanly

    But this will give me the first C1 ie C12 it doesn't distinguish between C1, C11, C10 or C19.
    I need to be able to search for C1 not C10. The range will be M9:M65535 every time. But the content changes with every application. The M column is not filtered in order and can have blanks also. I have only shown 3 here but there could be 10,000 rows. each with any number of parts listed with comma separators.

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: searching in a string for text cleanly

    This is a custom function, e.g use as =x(A1,"C1"). By the way, always best to try code before declaring that it won't work...
    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: searching in a string for text cleanly

    Quote Originally Posted by tmd_63 View Post
    But this will give me the first C1 ie C12 it doesn't distinguish between C1, C11, C10 or C19.
    That's impossible.
    It should like attached.
    Attached Files Attached Files
    Last edited by jindon; 07-22-2016 at 07:35 AM.

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: searching in a string for text cleanly

    Quote Originally Posted by tmd_63 View Post
    there could be 10,000 rows.
    And if you want only first match then
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-12-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: searching in a string for text cleanly

    Sorry. I couldn't get it to work as it is a range from M9 to M??? and I cannot select the range first. This is to be run in code.
    Also, the company restricts macros and VBScripts for security reasons.

  8. #8
    Registered User
    Join Date
    08-12-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: searching in a string for text cleanly

    Sorry. I couldn't get it to work as it is a range from M9 to M??? and I cannot select the range first. This is to be run in code.
    Also, the company restricts macros and VBScripts for security reasons.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: searching in a string for text cleanly

    Then I don't know how to do it without vba... perhaps very complex formula I hope.

  10. #10
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: searching in a string for text cleanly

    So why post a question in a VBA forum?

  11. #11
    Registered User
    Join Date
    08-12-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: searching in a string for text cleanly

    I tried this. It appears to work if I am on the same sheet, but not if I am in a different sheet.
    Please Login or Register  to view this content.
    I get a run time error 1004
    Select method of Range class failed.
    I need to run the code from any sheet but the search is inside sheet2 (for this part).

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: searching in a string for text cleanly

    In that case, no need to Select.
    Change to
    Please Login or Register  to view this content.
    But this should be faster:
    Please Login or Register  to view this content.
    Last edited by jindon; 07-22-2016 at 09:09 AM.

  13. #13
    Registered User
    Join Date
    08-12-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: searching in a string for text cleanly

    Perfect thanks. That got it that time.

+ 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. Searching for a numbers from right within a text string
    By don manual in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 02-22-2014, 08:59 PM
  2. Searching for a number within a text string
    By pauldaddyadams in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-19-2012, 12:12 PM
  3. Searching for text in a string
    By Jedski in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-10-2012, 03:44 PM
  4. Searching for a numeric value in a text string
    By Uncle heFTy in forum Excel General
    Replies: 2
    Last Post: 08-17-2011, 02:39 AM
  5. Searching for text string
    By wit2001large in forum Excel General
    Replies: 6
    Last Post: 02-10-2011, 10:25 AM
  6. Searching a string of text and displaying it's corresponding value
    By ole_gunner11 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-16-2010, 07:46 AM
  7. Searching a String of text for a character...
    By NewExcelUser in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-24-2006, 05:39 AM
  8. Cleanly Trimming text...
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-28-2006, 09:25 AM

Tags for this Thread

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