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  

EXCEL: How to scan text reversed (like ACCESS: InStrRev)?



 
 
Thread Tools Display Modes
  #1  
Old August 21st, 2007, 02:22 AM posted to microsoft.public.excel.worksheet.functions
4mula_freak[_2_]
external usenet poster
 
Posts: 1
Default EXCEL: How to scan text reversed (like ACCESS: InStrRev)?

Immediate Purpose: To do a right-to-left scan in EXCEL formula operating
on another text field, similar to what's allowed in ACCESS query formula with
InStrRev function. Why? Often for text fields, like people names, streets,
etc., parsing is easier if can scan text reversed. More quickly isolates
last name root, or maybe one suffix. FIND's Left to right scan is messier to
wade through all variations of first, middle (or not), and/or last name
prefix, if any.
A work-around is possible but very bulky. I use a formula to create my
own reversed text. Then use normal left-to-right FIND on it, and offset
FIND's result against LENgth of forward text field to get desired answer.
How bulky: For a 30-byte name field, you'd need a reversing formula 641
bytes long, with 30 terms in it: =mid(F3,len(F3)-0,1)&mid(F3,len(F3)-1,1)&...
&mid(F3,len(F3)-29,1). (I actually use another formula to build this one.)
General Purpose: Chop up data easiest way possible to separately field
portions of it. Important in data acquisition and text data analysis.
Examples are parsing raw files to load databases, or isolating patterns for
fraud forensics, etc.

  #2  
Old August 21st, 2007, 02:57 AM posted to microsoft.public.excel.worksheet.functions
Ron Rosenfeld
external usenet poster
 
Posts: 3,719
Default EXCEL: How to scan text reversed (like ACCESS: InStrRev)?

On Mon, 20 Aug 2007 18:22:02 -0700, 4mula_freak 4mula
wrote:

Immediate Purpose: To do a right-to-left scan in EXCEL formula operating
on another text field, similar to what's allowed in ACCESS query formula with
InStrRev function. Why? Often for text fields, like people names, streets,
etc., parsing is easier if can scan text reversed. More quickly isolates
last name root, or maybe one suffix. FIND's Left to right scan is messier to
wade through all variations of first, middle (or not), and/or last name
prefix, if any.
A work-around is possible but very bulky. I use a formula to create my
own reversed text. Then use normal left-to-right FIND on it, and offset
FIND's result against LENgth of forward text field to get desired answer.
How bulky: For a 30-byte name field, you'd need a reversing formula 641
bytes long, with 30 terms in it: =mid(F3,len(F3)-0,1)&mid(F3,len(F3)-1,1)&...
&mid(F3,len(F3)-29,1). (I actually use another formula to build this one.)
General Purpose: Chop up data easiest way possible to separately field
portions of it. Important in data acquisition and text data analysis.
Examples are parsing raw files to load databases, or isolating patterns for
fraud forensics, etc.




You could use a UDF to reverse the string, at least in later versions (2000+)
of Excel.

==========================
Function Reverse(str As String) As String
Reverse = StrReverse(str)
End Function
===========================

InStrRev is also a function in Excel VBA.

For even more flexibility, you could use a UDF implementing Regular Expressions
(Microsoft VBScript Regular Expressions 5.5).

Or you could download and install Longre's free morefunc.xll add-in from
http://xcell05.free.fr However, some of the add-in functions won't work in
versions later than Excel 2003 (I'm not sure about the Regex functions) and it
won't handle strings greater than 255 characters in length.

One of the Regular Expression solutions makes parsing a text string a fairly
simple task.

Let me know which you want more information about.
--ron
  #3  
Old August 21st, 2007, 03:58 AM posted to microsoft.public.excel.worksheet.functions
4mula freak
external usenet poster
 
Posts: 4
Default EXCEL: How to scan text reversed (like ACCESS: InStrRev)?

I like the simplicity of the 3 line UDF you suggested. Another respondent did
too (JMB). I didn't know about StrReverse() in VBA. But I knew about
InStrRev() in ACCESS database -- it's a directly usable in-formula function
for any ACCESS query. I've not set up a UDF before, but I'll try the HELP
hints on that first.
Thanks for your quick response, Ron! ...Steve

"Ron Rosenfeld" wrote:

On Mon, 20 Aug 2007 18:22:02 -0700, 4mula_freak 4mula
wrote:

Immediate Purpose: To do a right-to-left scan in EXCEL formula operating
on another text field, similar to what's allowed in ACCESS query formula with
InStrRev function. Why? Often for text fields, like people names, streets,
etc., parsing is easier if can scan text reversed. More quickly isolates
last name root, or maybe one suffix. FIND's Left to right scan is messier to
wade through all variations of first, middle (or not), and/or last name
prefix, if any.
A work-around is possible but very bulky. I use a formula to create my
own reversed text. Then use normal left-to-right FIND on it, and offset
FIND's result against LENgth of forward text field to get desired answer.
How bulky: For a 30-byte name field, you'd need a reversing formula 641
bytes long, with 30 terms in it: =mid(F3,len(F3)-0,1)&mid(F3,len(F3)-1,1)&...
&mid(F3,len(F3)-29,1). (I actually use another formula to build this one.)
General Purpose: Chop up data easiest way possible to separately field
portions of it. Important in data acquisition and text data analysis.
Examples are parsing raw files to load databases, or isolating patterns for
fraud forensics, etc.




You could use a UDF to reverse the string, at least in later versions (2000+)
of Excel.

==========================
Function Reverse(str As String) As String
Reverse = StrReverse(str)
End Function
===========================

InStrRev is also a function in Excel VBA.

For even more flexibility, you could use a UDF implementing Regular Expressions
(Microsoft VBScript Regular Expressions 5.5).

Or you could download and install Longre's free morefunc.xll add-in from
http://xcell05.free.fr However, some of the add-in functions won't work in
versions later than Excel 2003 (I'm not sure about the Regex functions) and it
won't handle strings greater than 255 characters in length.

One of the Regular Expression solutions makes parsing a text string a fairly
simple task.

Let me know which you want more information about.
--ron

  #4  
Old August 21st, 2007, 01:19 PM posted to microsoft.public.excel.worksheet.functions
Ron Rosenfeld
external usenet poster
 
Posts: 3,719
Default EXCEL: How to scan text reversed (like ACCESS: InStrRev)?

On Mon, 20 Aug 2007 19:58:01 -0700, 4mula freak
wrote:

I like the simplicity of the 3 line UDF you suggested. Another respondent did
too (JMB). I didn't know about StrReverse() in VBA. But I knew about
InStrRev() in ACCESS database -- it's a directly usable in-formula function
for any ACCESS query. I've not set up a UDF before, but I'll try the HELP
hints on that first.
Thanks for your quick response, Ron! ...Steve


Steve,

To set up a UDF:

alt-F11 opens the VB Editor
Ensure your project is highlighted in the Project Explorer window, then
Insert/Module and paste the code into the window that opens.

To use the UDF, in some cell on your worksheet, merely enter =Reverse(cell_ref)
(Or =Reverse(string))

To use the UDF in multiple workbooks, I save it as an add-in (.xla) and then
enable that add-in in Excel.

Enjoy.

--ron
 




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 10:53 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.