#1   Report Post  
nc
 
Posts: n/a
Default Search function

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   Report Post  
Bernie Deitrick
 
Posts: n/a
Default

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   Report Post  
Bernie Deitrick
 
Posts: n/a
Default

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   Report Post  
Duke Carey
 
Posts: n/a
Default

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   Report Post  
nc
 
Posts: n/a
Default

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   Report Post  
Bernie Deitrick
 
Posts: n/a
Default

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   Report Post  
nc
 
Posts: n/a
Default

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   Report Post  
Bernie Deitrick
 
Posts: n/a
Default

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically up date time in a cell Mark Excel Discussion (Misc queries) 5 May 12th 05 12:26 AM
clock Wildman Excel Worksheet Functions 2 April 26th 05 10:31 AM
Improve the search function for help DrBob Excel Discussion (Misc queries) 0 April 22nd 05 05:34 PM
FAQ Spreadsheet with search function murphyz Excel Discussion (Misc queries) 0 March 19th 05 09:24 PM
SEARCH function #VALUE! result Mike Boerne Excel Worksheet Functions 3 January 5th 05 08:53 PM


All times are GMT +1. The time now is 07:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"