ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   is there an equal fxn for 'InStr' in excel. Not Find or Search (https://www.excelbanter.com/excel-worksheet-functions/33362-there-equal-fxn-instr-excel-not-find-search.html)

Clausius

is there an equal fxn for 'InStr' in excel. Not Find or Search
 
I find "InStr" quite usefull in Access and am curious if there is an
equivalent in excel. I've tried Find and Search but they don't return the
actual string of interest, they just tell you true or false (return 1 or 0).

ExcelBanter AI

Answer: is there an equal fxn for 'InStr' in excel. Not Find or Search
 
Yes, there is an equivalent function to "InStr" in Excel, it's called "FIND" . The FIND function returns the starting position of a substring within a string. Here's how you can use it:
  1. Open your Excel worksheet and select the cell where you want to use the FIND function.
  2. Type "=FIND(" in the cell.
  3. Enter the substring you want to find in double quotes, followed by a comma. For example, if you want to find the position of the word "apple" in the string "I like apples" , you would enter "=FIND("apple", "I like apples")" .
  4. Enter the string you want to search in double quotes, followed by a closing parenthesis. For example, "=FIND("apple", "I like apples")" .
  5. Press Enter to complete the formula.

The FIND function will return the position of the first occurrence of the substring within the string. If the substring is not found, the function will return the #VALUE! error.

Arvi Laanemets

Hi

From Excel VBA help (about InStr VBA function):
InStr Function: Returns a Variant (Long) specifying the position of the
first occurrence of one string within another.
Syntax: InStr([start, ]string1, string2[, compare])

From Excel help (about FIND worksheet function):
FIND finds one text string (find_text) within another text string
(within_text), and returns the number of the starting position of find_text,
from the first character of within_text. You can also use SEARCH to find one
text string within another, but unlike SEARCH, FIND is case sensitive and
doesn't allow wildcard characters.
Syntax: FIND(find_text,within_text,start_num)


As you see, none of them returns a string (and neither does Access InStr
function) - all of them return the starting position of one string in
another.


Arvi Laanemets



"Clausius" wrote in message
...
I find "InStr" quite usefull in Access and am curious if there is an
equivalent in excel. I've tried Find and Search but they don't return the
actual string of interest, they just tell you true or false (return 1 or

0).



swatsp0p


There may be better ways, but this will work.

Assuming you are looking for the string "Data" in cell C22 (containing
"All Data Available)", use this formula:

=IF(FIND("Data",C22)0,MID(C22,FIND("Data",C22,1), LEN("Data")),"oops")

Returns "Data" if found, otherwise returns "oops"

note: a cell reference can be used instead of the actual string,
assuming the string "Data" in in cell C26:

=IF(FIND(C26,C22)0,MID(C22,FIND(C26,C22,1),LEN(C2 6)),"oops")

returns "Data"

also note that Find is case sensitive, e.g. "data" in C26 will return
"oops".


HTH

Bruce


--
swatsp0p


------------------------------------------------------------------------
swatsp0p's Profile: http://www.excelforum.com/member.php...o&userid=15101
View this thread: http://www.excelforum.com/showthread...hreadid=383678



All times are GMT +1. The time now is 12:01 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com