Find last instance of character in text
It returns an array of 1 through whatever the length of A1 is, so if Len(A1)
= 7, the Row(Indirect("1:"&Len(A1))) returns an array of 1, 2, 3, 4, 5, 6, 7.
Mid(A1, Row(Indirect("1:"&Len(A1))), 1) = ":"
evaluates each character of A1 and returns True/False (True for characters
that =":"). Excel stores True as 1 and False as 0. So this array of 1's and
0's is multiplied by the Row(Indirect.....) to get an array of 0's and
nonzero numbers (the nonzeros being the character positions of the ":"'s).
Then the Max function is used on this array to return the character position
of the last ":"
Generally, array formulae take longer to calculate, so you should consider
that before using it. After playing around a little out of curiosity, Biff's
suggestion seems to be about 5.5 times faster than the my suggestion and
twice as fast as daddylonglegs.
"KonaAl" wrote:
Wow! That worked great. I have no idea what the row(indirect... means but
it worked. Thanks a lot!
Allan
"JMB" wrote:
Just change the cell references from A1 to C6.
"KonaAl" wrote:
Thanks for the reply, JMB. Assuming the "1:" s/b ":1", I couldn't get this
to work. I tried changing the A1 references to C6, for example, and still
got a #REF! error. Both times I entered as an array.
Even after looking at the help files for ROW and INDIRECT, I can't figure
this out. Your help is appreciated.
Allan
"JMB" wrote:
One way
=MAX((MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)=":")*( ROW(INDIRECT("1:"&LEN(A1)))))
entered using Cntrl+Shift+Enter or you will get 0 or 1.
"KonaAl" wrote:
Hi All,
I need to be able to return an account number (7 digits) from a text string.
The account number is preceded by a colon. I'm very familiar with find,
left, len, right functions, etc. My problem is the there can be several
colons in the string and the position changes. For example:
Text 1
1000000 · Cash & Cash Equivalents:1010000 · Cash Accounts:1012000 ·
IBT:1012600 · IBT Cash {WF}
Text 2
1000000 · Cash & Cash Equivalents:1010000 · Cash Accounts:1013000 · IBT - B
of A
What I need is 1012600 from the first string and 1013000 from the second.
I can't figure out how to obtain the position of the last colon in the string.
TIA,
Allan
|