Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default seperating values from text

On Mon, 15 Jan 2007 05:59:01 -0800, enyaw
wrote:

There may be more than two items in the cell. The data will always be
word/space/number/space/word/space/number and the same for any more items
added.


Here's one way, then.

Download and install Longre's free morefunc.xll add-in from
http://xcell05.free.fr

Then you can use one of these two formulas (I'm not sure which one is faster).
These formulas use Regular Expressions to extract the numeric values from the
strings.

They will extract all numbers.

If you might have a number in the "word" portion, that you wish to have
ignored, (e.g. wo23rd 658 wo5rd 123) and you want to ignore the 23 and the 5,
but add the 658 and 123, some further changes will be required in the "Regex".



The **array** formula:

=SUM(--REGEX.MID(A1,"\d+",INTVECTOR(REGEX.COUNT(A1,"\d+") ,1)))

(To enter an array formula, hold down <ctrl<shift when you hit <enter.
Excel will place braces {...} around the formula).

Or the non-array formula:

=EVAL(MCONCAT(REGEX.MID(A1,"\d+",INTVECTOR(REGEX.C OUNT(A1,"\d+"),1)),"+"))

You did not answer my question as to whether the numbers would be integers or
not. The above formula will work for integers. If the values may include
decimals, and/or be positive or negative, then instead of "\d+" you should
substitute the following:

"[-+]?(\d*\.)?\d+"

which would result in

**array entered**:

=SUM(--REGEX.MID(A1,"[-+]?(\d*\.)?\d+",
INTVECTOR(REGEX.COUNT(A1,"[-+]?(\d*\.)?\d+"),1)))

OR normally entered:

=EVAL(MCONCAT(REGEX.MID(A1,"[-+]?(\d*\.)?\d+",
INTVECTOR(REGEX.COUNT(A1,"[-+]?(\d*\.)?\d+"),1)),"+"))





--ron
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default seperating values from text

On Mon, 15 Jan 2007 10:15:10 -0500, Ron Rosenfeld
wrote:

On Mon, 15 Jan 2007 05:59:01 -0800, enyaw
wrote:

There may be more than two items in the cell. The data will always be
word/space/number/space/word/space/number and the same for any more items
added.


Here's one way, then.

Download and install Longre's free morefunc.xll add-in from
http://xcell05.free.fr

Then you can use one of these two formulas (I'm not sure which one is faster).
These formulas use Regular Expressions to extract the numeric values from the
strings.

They will extract all numbers.

If you might have a number in the "word" portion, that you wish to have
ignored, (e.g. wo23rd 658 wo5rd 123) and you want to ignore the 23 and the 5,
but add the 658 and 123, some further changes will be required in the "Regex".



The **array** formula:

=SUM(--REGEX.MID(A1,"\d+",INTVECTOR(REGEX.COUNT(A1,"\d+") ,1)))

(To enter an array formula, hold down <ctrl<shift when you hit <enter.
Excel will place braces {...} around the formula).

Or the non-array formula:

=EVAL(MCONCAT(REGEX.MID(A1,"\d+",INTVECTOR(REGEX. COUNT(A1,"\d+"),1)),"+"))

You did not answer my question as to whether the numbers would be integers or
not. The above formula will work for integers. If the values may include
decimals, and/or be positive or negative, then instead of "\d+" you should
substitute the following:

"[-+]?(\d*\.)?\d+"

which would result in

**array entered**:

=SUM(--REGEX.MID(A1,"[-+]?(\d*\.)?\d+",
INTVECTOR(REGEX.COUNT(A1,"[-+]?(\d*\.)?\d+"),1)))

OR normally entered:

=EVAL(MCONCAT(REGEX.MID(A1,"[-+]?(\d*\.)?\d+",
INTVECTOR(REGEX.COUNT(A1,"[-+]?(\d*\.)?\d+"),1)),"+"))





--ron



And if numbers may be in the "word"s, then try this regex instead:

"[-+]?\b(\d*\.)?\d+\b"


--ron
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default seperating values from text

On Mon, 15 Jan 2007 10:31:45 -0500, Ron Rosenfeld
wrote:




And if numbers may be in the "word"s, then try this regex instead:

"[-+]?\b(\d*\.)?\d+\b"



I should amplify that the above regex will "ignore" numbers that are embedded
within words. The original variations will "include" those numbers.

--ron
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
Link Protected WorkBook ... and Get #N/A for Text Values! monir Excel Discussion (Misc queries) 5 April 26th 06 12:37 AM
Can anyone tell me how to hide rows that have 0 values and text. Aussie Charts and Charting in Excel 2 April 13th 06 10:57 AM
How do I LOOKUP text values Amber C-W Excel Worksheet Functions 4 July 20th 05 05:27 PM
Count how many different text values in an array. OVERLOAD Excel Worksheet Functions 3 April 14th 05 04:12 PM
Help adding text values Texas-DC_271 Excel Worksheet Functions 7 January 15th 05 11:14 PM


All times are GMT +1. The time now is 02:30 AM.

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"