Home |
Search |
Today's Posts |
#1
![]() |
|||
|
|||
![]()
Hi
The following function reads from left to right SEARCH(find_text,within_text,start_num) Can anyone please help I need the same function but reading from right to left. Thanks. |
#2
![]() |
|||
|
|||
![]()
nc,
You can use a user-defined-function. Copy the code below, and paste it into a module in your workbook. Then use it like: =RSEARCH(find_text,within_text) =RSEARCH("Bernie","Bernie, you are Bernie") =RSEARCH(A2, A1) And, if you don't like UDF's then you can use the array function (entered with Ctrl-Shift-Enter) =MAX(IF(ISERROR(SEARCH(A2,A1,ROW(INDIRECT("A1:A"&L EN(A1))))),0,SEARCH(A2,A1, ROW(INDIRECT("A1:A"&LEN(A1)))))) where A1 is the string to be searched, and A2 is the string to be found, for both of the above cases. HTH, Bernie MS Excel MVP Public Function RSearch(strFindText As String, _ strWithinText As String) As Integer Dim i As Integer For i = Len(strWithinText) To 1 Step -1 If InStr(i, strWithinText, strFindText) 0 Then RSearch = i Exit Function End If Next i End Function "nc" wrote in message ... Hi The following function reads from left to right SEARCH(find_text,within_text,start_num) Can anyone please help I need the same function but reading from right to left. Thanks. |
#3
![]() |
|||
|
|||
![]()
And note, if you are adapting this for other cells, only change the direct
cell references: the A2, A1, and LEN(A1) parts. Leave the "A1:A" parts in the INDIRECT function alone. HTH, Bernie MS Excel MVP "Bernie Deitrick" <deitbe @ consumer dot org wrote in message ... nc, You can use a user-defined-function. Copy the code below, and paste it into a module in your workbook. Then use it like: =RSEARCH(find_text,within_text) =RSEARCH("Bernie","Bernie, you are Bernie") =RSEARCH(A2, A1) And, if you don't like UDF's then you can use the array function (entered with Ctrl-Shift-Enter) =MAX(IF(ISERROR(SEARCH(A2,A1,ROW(INDIRECT("A1:A"&L EN(A1))))),0,SEARCH(A2,A1, ROW(INDIRECT("A1:A"&LEN(A1)))))) where A1 is the string to be searched, and A2 is the string to be found, for both of the above cases. HTH, Bernie MS Excel MVP Public Function RSearch(strFindText As String, _ strWithinText As String) As Integer Dim i As Integer For i = Len(strWithinText) To 1 Step -1 If InStr(i, strWithinText, strFindText) 0 Then RSearch = i Exit Function End If Next i End Function "nc" wrote in message ... Hi The following function reads from left to right SEARCH(find_text,within_text,start_num) Can anyone please help I need the same function but reading from right to left. Thanks. |
#4
![]() |
|||
|
|||
![]()
with the help of a simple user-defined function
=find("x",RightToLeft("Excel") = 4 Function RightToLeft(strRTL As String) As String RightToLeft = StrReverse(strRTL) End Function "nc" wrote: Hi The following function reads from left to right SEARCH(find_text,within_text,start_num) Can anyone please help I need the same function but reading from right to left. Thanks. |
#5
![]() |
|||
|
|||
![]()
Hi Bernie
I tried your code, it seem to be doing the search from left to right. "Bernie Deitrick" wrote: nc, You can use a user-defined-function. Copy the code below, and paste it into a module in your workbook. Then use it like: =RSEARCH(find_text,within_text) =RSEARCH("Bernie","Bernie, you are Bernie") =RSEARCH(A2, A1) And, if you don't like UDF's then you can use the array function (entered with Ctrl-Shift-Enter) =MAX(IF(ISERROR(SEARCH(A2,A1,ROW(INDIRECT("A1:A"&L EN(A1))))),0,SEARCH(A2,A1, ROW(INDIRECT("A1:A"&LEN(A1)))))) where A1 is the string to be searched, and A2 is the string to be found, for both of the above cases. HTH, Bernie MS Excel MVP Public Function RSearch(strFindText As String, _ strWithinText As String) As Integer Dim i As Integer For i = Len(strWithinText) To 1 Step -1 If InStr(i, strWithinText, strFindText) 0 Then RSearch = i Exit Function End If Next i End Function "nc" wrote in message ... Hi The following function reads from left to right SEARCH(find_text,within_text,start_num) Can anyone please help I need the same function but reading from right to left. Thanks. |
#6
![]() |
|||
|
|||
![]()
nc,
When I tested it, it returned the starting position of the last instance of the string I was searching for. Perhaps you could post the values that you are passing to the function(s)? HTH, Bernie MS Excel MVP "nc" wrote in message ... Hi Bernie I tried your code, it seem to be doing the search from left to right. "Bernie Deitrick" wrote: nc, You can use a user-defined-function. Copy the code below, and paste it into a module in your workbook. Then use it like: =RSEARCH(find_text,within_text) =RSEARCH("Bernie","Bernie, you are Bernie") =RSEARCH(A2, A1) And, if you don't like UDF's then you can use the array function (entered with Ctrl-Shift-Enter) =MAX(IF(ISERROR(SEARCH(A2,A1,ROW(INDIRECT("A1:A"&L EN(A1))))),0,SEARCH(A2,A1, ROW(INDIRECT("A1:A"&LEN(A1)))))) where A1 is the string to be searched, and A2 is the string to be found, for both of the above cases. HTH, Bernie MS Excel MVP Public Function RSearch(strFindText As String, _ strWithinText As String) As Integer Dim i As Integer For i = Len(strWithinText) To 1 Step -1 If InStr(i, strWithinText, strFindText) 0 Then RSearch = i Exit Function End If Next i End Function "nc" wrote in message ... Hi The following function reads from left to right SEARCH(find_text,within_text,start_num) Can anyone please help I need the same function but reading from right to left. Thanks. |
#7
![]() |
|||
|
|||
![]()
Bernie
A1=excel B1=RSearch("x",A1) the value the function is returning is 2, I was expecting 4. "Bernie Deitrick" wrote: nc, When I tested it, it returned the starting position of the last instance of the string I was searching for. Perhaps you could post the values that you are passing to the function(s)? HTH, Bernie MS Excel MVP "nc" wrote in message ... Hi Bernie I tried your code, it seem to be doing the search from left to right. "Bernie Deitrick" wrote: nc, You can use a user-defined-function. Copy the code below, and paste it into a module in your workbook. Then use it like: =RSEARCH(find_text,within_text) =RSEARCH("Bernie","Bernie, you are Bernie") =RSEARCH(A2, A1) And, if you don't like UDF's then you can use the array function (entered with Ctrl-Shift-Enter) =MAX(IF(ISERROR(SEARCH(A2,A1,ROW(INDIRECT("A1:A"&L EN(A1))))),0,SEARCH(A2,A1, ROW(INDIRECT("A1:A"&LEN(A1)))))) where A1 is the string to be searched, and A2 is the string to be found, for both of the above cases. HTH, Bernie MS Excel MVP Public Function RSearch(strFindText As String, _ strWithinText As String) As Integer Dim i As Integer For i = Len(strWithinText) To 1 Step -1 If InStr(i, strWithinText, strFindText) 0 Then RSearch = i Exit Function End If Next i End Function "nc" wrote in message ... Hi The following function reads from left to right SEARCH(find_text,within_text,start_num) Can anyone please help I need the same function but reading from right to left. Thanks. |
#8
![]() |
|||
|
|||
![]()
nc,
Oh, I thought you wanted to find the rightmost value: =RSearch("x","Exactly exxxxxxxtincxxxt") to return the position of the last x. For your actaul problem, simply use =LEN(A1) - SEARCH("x",A1) +1 Forget all that other stuff.... HTH, Bernie MS Excel MVP "nc" wrote in message ... Bernie A1=excel B1=RSearch("x",A1) the value the function is returning is 2, I was expecting 4. "Bernie Deitrick" wrote: nc, When I tested it, it returned the starting position of the last instance of the string I was searching for. Perhaps you could post the values that you are passing to the function(s)? HTH, Bernie MS Excel MVP "nc" wrote in message ... Hi Bernie I tried your code, it seem to be doing the search from left to right. "Bernie Deitrick" wrote: nc, You can use a user-defined-function. Copy the code below, and paste it into a module in your workbook. Then use it like: =RSEARCH(find_text,within_text) =RSEARCH("Bernie","Bernie, you are Bernie") =RSEARCH(A2, A1) And, if you don't like UDF's then you can use the array function (entered with Ctrl-Shift-Enter) =MAX(IF(ISERROR(SEARCH(A2,A1,ROW(INDIRECT("A1:A"&L EN(A1))))),0,SEARCH(A2,A1, ROW(INDIRECT("A1:A"&LEN(A1)))))) where A1 is the string to be searched, and A2 is the string to be found, for both of the above cases. HTH, Bernie MS Excel MVP Public Function RSearch(strFindText As String, _ strWithinText As String) As Integer Dim i As Integer For i = Len(strWithinText) To 1 Step -1 If InStr(i, strWithinText, strFindText) 0 Then RSearch = i Exit Function End If Next i End Function "nc" wrote in message ... Hi The following function reads from left to right SEARCH(find_text,within_text,start_num) Can anyone please help I need the same function but reading from right to left. Thanks. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Automatically up date time in a cell | Excel Discussion (Misc queries) | |||
clock | Excel Worksheet Functions | |||
Improve the search function for help | Excel Discussion (Misc queries) | |||
FAQ Spreadsheet with search function | Excel Discussion (Misc queries) | |||
SEARCH function #VALUE! result | Excel Worksheet Functions |