+ Reply to Thread
Results 1 to 15 of 15

Does not cosistantly find a text string using "InStr" function

  1. #1
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    384

    Does not cosistantly find a text string using "InStr" function

    This has my head spinning as it works in some cases and not in others. I am using the "instr" function to a word I am looking for. When found the result is greater than "0". Here are two examples of what is and is not working. "Taxes - Property" is in one cell and it finds it and "Payroll Taxes" is in another and does not find it. The same for the second example.

    Example 1
    Please Login or Register  to view this content.
    "Taxes - Property" (without quotes) (finds)
    "Payroll Taxes" (without quotes) (does not find)

    Example 2
    Please Login or Register  to view this content.
    "Depreciation Expense" (without quotes) (finds)
    "Depreciation Expense (Depreciation on equipment, buildings and improvements)" (without quotes)(does not find)

    Is there another parameter I have set incorrectly?
    Last edited by Bobbbo; 03-21-2016 at 01:44 PM. Reason: Mark it solved

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,834

    Re: Does not cosistantly find a text string using "InStr" function

    Your third argument is " Taxes " (note the space character at start and end of string).
    The string "Payroll Taxes" does not contain the text string " Taxes " with a space character before and after the word Taxes. It contains the string " Taxes" (space before but not after), but this is not what you have asked it to look for.
    The InStr function is working correctly. You need to decide exactly what purpose those extra space characters serve and what to do with them.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    384

    Re: Does not cosistantly find a text string using "InStr" function

    The reason for the space, which has been work very well, is to avoid pulling the word out of the middle of another word. If you look ate the second example the start the exact same, but it is found in one but not the other.

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,834

    Re: Does not cosistantly find a text string using "InStr" function

    I cannot replicate the problem. It finds " Depreciation " just fine in both cases.

    Possible that there are "non-breaking" spaces or other non-printing characters in the search string?

    It might be helpful to upload a sample spreadsheet with the actual text strings being tested.

  5. #5
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    384

    Re: Does not cosistantly find a text string using "InStr" function

    I will do that. See attached
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,834

    Re: Does not cosistantly find a text string using "InStr" function

    Still cannot replicate the problem. In both cases, it finds " Taxes " just fine.

  7. #7
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    384

    Re: Does not cosistantly find a text string using "InStr" function

    Strange, my computer does not. Could there be something broken in my excel?

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,834

    Re: Does not cosistantly find a text string using "InStr" function

    I expect it is "possible", but there is no way we can know on this side of the internet. I did get a warning message about this file's format not matching its extension, though the file opened just fine. Does it work correctly if you start from a clean, new file?

    All you have provided are code snippets and one example that worked. Are there more examples? Is there more to the code?

    This worked correctly for me.
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    384

    Re: Does not cosistantly find a text string using "InStr" function

    I have no idea what is going on. I get the same message when opening up the file. I reset my computer and even save the file as another name and the message went away.

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Does not cosistantly find a text string using "InStr" function

    It does not matter if you have a space or not, nor does if it is case sensitive as long as you have option compare 1.

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    384

    Re: Does not cosistantly find a text string using "InStr" function

    It turns out to be a problem on my part. Thanks all for the help. AS33, are you certain that you do not need a space. If the sting I am looking for is "def" and and the cell has "ABCDEFHIJ" I do not want it to say found even though "DEF" is within the string.

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

    Re: Does not cosistantly find a text string using "InStr" function

    See if this works correctly on you side.
    Result should be True/True/False

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    384

    Re: Does not cosistantly find a text string using "InStr" function

    Hi AB33. Are you saying your code:

    Please Login or Register  to view this content.
    will work better than mine?

    Please Login or Register  to view this content.

  14. #14
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Does not cosistantly find a text string using "InStr" function

    Yes, you do not need to complicate by adding upper cases as long as you have added option compare insensitive (that is 1)

  15. #15
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    384

    Re: Does not cosistantly find a text string using "InStr" function

    AB33, Thanks!

+ 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. How to use InStr function to search for a text that starts with "CTF" and ends with "."?
    By yoursamrit2000 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-27-2014, 06:52 PM
  2. Replies: 1
    Last Post: 08-15-2014, 06:00 AM
  3. Replies: 0
    Last Post: 03-21-2014, 09:58 AM
  4. [SOLVED] Find text string after the ", " then move its down to the last row
    By tuongtu3 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-15-2013, 08:09 PM
  5. Instr() function giving error: "Type mismatch"
    By arjun.majumdar in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-22-2013, 04:17 AM
  6. [SOLVED] Search numbers in a text string, find largest "value" return a value
    By OilGasKing in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-27-2013, 09:01 PM
  7. Replies: 4
    Last Post: 09-06-2012, 02:37 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