A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Worksheet Functions
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

How to find the last occurence of a character



 
 
Thread Tools Display Modes
  #1  
Old June 23rd, 2004, 03:08 PM
Mike
external usenet poster
 
Posts: n/a
Default How to find the last occurence of a character

Hi,

I'd like to find the last occurence of a given character in a String.

For example, if cell A1 contains This.Package.Name.Class, I'd like to find the last period position (18).

The text function FIND doesn't permit that and I can't find a text function that does a reverse FIND or a text function that can reverse the content of a cell before FINDing things in it.

Thanks,

Mike.
  #2  
Old June 23rd, 2004, 03:26 PM
Andy B
external usenet poster
 
Posts: n/a
Default How to find the last occurence of a character

Hi

Do you want to return the text after it? If so, try this:
=MID(A1,FIND("^",SUBSTITUTE(A1,".","^",LEN(A1)-LEN(SUBSTITUTE(A1,".",""))))+
1,50)
This will return the 50 characters after the last dot.

--
Andy.


"Mike" wrote in message
...
Hi,

I'd like to find the last occurence of a given character in a String.

For example, if cell A1 contains This.Package.Name.Class, I'd like to find

the last period position (18).

The text function FIND doesn't permit that and I can't find a text

function that does a reverse FIND or a text function that can reverse the
content of a cell before FINDing things in it.

Thanks,

Mike.



  #3  
Old June 23rd, 2004, 03:38 PM
William
external usenet poster
 
Posts: n/a
Default How to find the last occurence of a character

Place the function below in a general module

Function findit(c As Range)
findit = Len(Left(c, Len(c) - Application.Find(".", StrReverse(c), 1) + 1))
End Function


Assuming the text is in cell A1, in another cell enter =findit(A1) to
return the position of the last period in cell A1. [You may need Excel 2002
or later]

--
XL2002
Regards

William



"Mike" wrote in message
...
| Hi,
|
| I'd like to find the last occurence of a given character in a String.
|
| For example, if cell A1 contains This.Package.Name.Class, I'd like to find
the last period position (18).
|
| The text function FIND doesn't permit that and I can't find a text
function that does a reverse FIND or a text function that can reverse the
content of a cell before FINDing things in it.
|
| Thanks,
|
| Mike.


  #4  
Old June 23rd, 2004, 03:43 PM
Daniel.M
external usenet poster
 
Posts: n/a
Default How to find the last occurence of a character

Hi Mike,

One way, with your string in A1, this Array formula (Ctrl-Shift-Array):

=MAX(IF(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)=".", ROW(INDIRECT("1:"&LEN(A1)))))

Regards,

Daniel M.

"Mike" wrote in message
...
Hi,

I'd like to find the last occurence of a given character in a String.

For example, if cell A1 contains This.Package.Name.Class, I'd like to find the

last period position (18).

The text function FIND doesn't permit that and I can't find a text function

that does a reverse FIND or a text function that can reverse the content of a
cell before FINDing things in it.

Thanks,

Mike.



  #5  
Old June 23rd, 2004, 05:45 PM
Harlan Grove
external usenet poster
 
Posts: n/a
Default How to find the last occurence of a character

"Daniel.M" wrote...
One way, with your string in A1, this Array formula (Ctrl-Shift-Array):

=MAX(IF(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)="." ,ROW(INDIRECT("1:"&LEN(A1)))))


Shorter alternative, also an array formula,

=LEN(A1)+1-MATCH(".",MID(A1,LEN(A1)+1-ROW(INDIRECT("1:"&LEN(A1))),1),0)

The MAX formula returns 0 if no match is found. The LEN-MATCH formula returns
#N/A. The latter could be adapted to return 0 as

=LEN(A1)+1-MATCH(".",MID("."&A1,LEN(A1)+2-ROW(INDIRECT("1:"&(LEN(A1)+1))),1),0)

--
To top-post is human, to bottom-post and snip is sublime.
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


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


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.