Hi in Excel I have the following string inside a cell:
[JOB-20636]: Customer - RNG - Malta
I would look if the following string contains the string RNG. Do you know how to do it?
Assistant
Yes, you can check if the string "RNG" is present within the cell using the SEARCH or FIND function in Excel. Here's how you can do it:
Assume the string is in cell A1.
You can use the following formula to check if "RNG" is present:
SEARCH("RNG", A1) attempts to find the text "RNG" in the string contained in cell A1. If found, it returns the position of the first character of "RNG". If not found, it returns an error.
ISNUMBER(...) checks whether the result of SEARCH is a number (indicating that "RNG" was found).
The IF function then returns "Found" if "RNG" is present and "Not Found" if it is not.
Alternative using FIND
If you want a case-sensitive search, you can use the FIND function instead:
Just replace "A1" with the actual cell reference containing your text if it's different. Use whichever method suits your requirement for case sensitivity.
User
It is not working. Any Idea? I tried also with FIND(" RNG " ) to see if the spaces matter in this task
Assistant
If the formula is not working as expected, let's troubleshoot a bit. Here’s a comprehensive approach to ensure you find "RNG" in the string [JOB-20636]: Customer - RNG - Malta:
Check for Leading/Trailing Spaces
Sometimes, extra spaces can affect string searches. To eliminate issues with spacing, ensure you are looking specifically for the substring "RNG" without surrounding spaces.
Basic Search with SEARCH:
User
Still not working. SEARCH("RNG", A1) is returning A1, not a number. So I expect that we are having issue here.
Assistant
If SEARCH("RNG", A1) is returning the entire content of A1 instead of a numeric position, then it's likely that there is an error in the formula syntax.
The SEARCH function should return a numeric position (the starting position of the substring) or an error if the substring isn't found. If it's returning the entire contents instead, that indicates a potential formula structure issue.
However, since "TRIM()" removes leading and trailing spaces, if you think the space before and after "RNG" matters (within the string), don't use TRIM.
Verify the Format
Ensure that the string in the cell is indeed exactly as you expect. Copy the content from your string and paste it into the formula to ensure there are no additional hidden characters.
Case Sensitivity
Remember:
SEARCH is not case-sensitive.
FIND is case-sensitive. If you are using FIND, make sure the casing of "RNG" matches exactly.
Adjusting for Spaces
If you suspect that the string might contain spaces either before or after "RNG":
You can use * as a wildcard inside the SEARCH function:
If these aren’t producing the desired outcome, please double-check the string in A1 for exact characters, spaces, or special characters that may not be apparent. If you're still having issues, feel free to share how you're implementing this, and I may be able to help troubleshoot further!
Here’s a step-by-step approach to troubleshoot the formula:
Verify the Content of Cell A1:
Click on cell A1 and check that it contains the exact string [JOB-20636]: Customer - RNG - Malta without any leading/trailing spaces or unexpected characters, such as:
[JOB-20636]: Customer - RNG - Malta
Directly Test SEARCH:
In a blank cell, directly enter:
=SEARCH("RNG", A1)
This should return a number if "RNG" is found within that string:
If "RNG" starts from the 20th character, it will return 20.
If it is not found, the output should be a #VALUE! error.
Using an Alternative Method with FIND:
If you prefer or need to add case sensitivity, use:
=FIND("RNG", A1)
This will also return a number indicating the position of "RNG" if it's found or a #VALUE! error if not.
Using an IFERROR Wrapper:
If you want to handle potential errors more gracefully:
=IFERROR(SEARCH("RNG", A1), "Not Found")
This will return "Not Found" if "RNG" is not present instead of showing an error.
Example:
Ensure you execute this in a clean cell, and just to clarify, ensure that the syntax is correct and being placed in a new cell:
Lastly, ensure you are using a compatible version of Excel, as older or non-standard versions could behave differently. If the formula is still not behaving as expected, there might be something else peculiar about your setup.
Summary of Steps:
Verify the exact contents in A1.
Directly test SEARCH without conditions.
Use FIND as an alternative.
Use IFERROR for error handling.
Let me know how it goes or if the problem persists!