Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Find Space from Right [in cell formula]



I found a Jan 5 2009 post to find the FIRST space from the right using the
InStrRev function. I'd like to incorporate this in a cell's formula, not a
VBA function.

Is that possible?

--
Thanks for your reply & assistance.
Jimbo213
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Find Space from Right [in cell formula]


Hi,

To find the position in the string of last space use

=LEN(A1)-LEN(RIGHT(A1,LEN(A1)-SEARCH("@",SUBSTITUTE(A1,"
","@",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))))

or if you want the last word

=MID(A1,FIND(CHAR(22),SUBSTITUTE(A1," ",CHAR(22),LEN(A1)-LEN(SUBSTITUTE(A1,"
",""))))+1,255)



Mike

"Jimbo213" wrote:


I found a Jan 5 2009 post to find the FIRST space from the right using the
InStrRev function. I'd like to incorporate this in a cell's formula, not a
VBA function.

Is that possible?

--
Thanks for your reply & assistance.
Jimbo213

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Find Space from Right [in cell formula]



In VBA the command is:

A = Right(B, #ofSpacesFromRight)
where
A are the digits a # space from the right
B is the cell entry, variable or array before this operation

in your case:

A = Right(B, 1)

Hope this is helpful.



"Jimbo213" wrote:

I found a Jan 5 2009 post to find the FIRST space from the right using the
InStrRev function. I'd like to incorporate this in a cell's formula, not a
VBA function.

Is that possible?

--
Thanks for your reply & assistance.
Jimbo213

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Find Space from Right [in cell formula]


If the string to test is in A1, use the following array formula:

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

It will return the position of the last space in the text in cell A1.
If there is no space, it returns 0. If A1 is empty, you'll get a #REF
error.

Since this is an array formula, you must press CTRL SHIFT ENTER rather
than just ENTER when you first enter the formula and whenever you edit
it later. If you do this properly, Excel will display the formula
enclosed in curly braces { }. You do not type in the curly braces --
Excel inserts them automatically. For much more information about
array formulas, see www.cpearson.com/Excel/ArrayFormulas.aspx.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Thu, 25 Jun 2009 12:54:03 -0700, Jimbo213
wrote:


I found a Jan 5 2009 post to find the FIRST space from the right using the
InStrRev function. I'd like to incorporate this in a cell's formula, not a
VBA function.

Is that possible?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Find Space from Right [in cell formula]


On Thu, 25 Jun 2009 12:54:03 -0700, Jimbo213
wrote:


I found a Jan 5 2009 post to find the FIRST space from the right using the
InStrRev function. I'd like to incorporate this in a cell's formula, not a
VBA function.

Is that possible?



The position in the string of the last space (counting from the left as does
the INSTRREV VBA function):

=FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))



--ron


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Find Space from Right [in cell formula]


Here is yet another way...

=LEN(A1)-LEN(TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",99)),99)))

--
Rick (MVP - Excel)


"Jimbo213" wrote in message
...

I found a Jan 5 2009 post to find the FIRST space from the right using the
InStrRev function. I'd like to incorporate this in a cell's formula, not
a
VBA function.

Is that possible?

--
Thanks for your reply & assistance.
Jimbo213


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Find Space from Right [in cell formula]



Ok great ...
Now, how do you modify that to find the SECOND space from the right?

--
Thanks for your reply & assistance.
Jimbo213


"Rick Rothstein" wrote:

Here is yet another way...

=LEN(A1)-LEN(TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",99)),99)))

--
Rick (MVP - Excel)


"Jimbo213" wrote in message
...

I found a Jan 5 2009 post to find the FIRST space from the right using the
InStrRev function. I'd like to incorporate this in a cell's formula, not
a
VBA function.

Is that possible?

--
Thanks for your reply & assistance.
Jimbo213



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Find Space from Right [in cell formula]



Thanks, I assume you meant "counting from the right ... as InstrRev"

How would you modify that to find the SECOND space from the right?

--
Thanks for your reply & assistance.
Jimbo213


"Ron Rosenfeld" wrote:

On Thu, 25 Jun 2009 12:54:03 -0700, Jimbo213
wrote:


I found a Jan 5 2009 post to find the FIRST space from the right using the
InStrRev function. I'd like to incorporate this in a cell's formula, not a
VBA function.

Is that possible?



The position in the string of the last space (counting from the left as does
the INSTRREV VBA function):

=FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))



--ron

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Find Space from Right [in cell formula]


On Fri, 26 Jun 2009 06:27:02 -0700, Jimbo213
wrote:

Thanks, I assume you meant "counting from the right ... as InstrRev"


You may be misunderstanding how InstrRev works (or perhaps I wasn't clear).

The value that InstrRev returns is the position of the "SearchFor" string (or,
in this case, <space). However, that value is the position in the full
string counting from the left.

For example, looking for the last space using InstrRev:

Now is the Time == 11

11 is the 11th character counting from the left


How would you modify that to find the SECOND space from the right?

--




=FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-n))

where "n" is the 0-based count of spaces from the right. So for the 1st space
from the right:

=FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-0))

second space from the right:

=FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-1))

etc.


--ron
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Find Space from Right [in cell formula]



I appreciate your reply, Ron, and I do understand that the first space from
the right in "Now is the Time" == 11

My question is how can the formula be modified to find the second space from
the right ... Now is the Time == 7 [between 'is the' ]

Thanks for your reply & assistance.
Jimbo213


"Ron Rosenfeld" wrote:

On Fri, 26 Jun 2009 06:27:02 -0700, Jimbo213
wrote:

Thanks, I assume you meant "counting from the right ... as InstrRev"


You may be misunderstanding how InstrRev works (or perhaps I wasn't clear).

The value that InstrRev returns is the position of the "SearchFor" string (or,
in this case, <space). However, that value is the position in the full
string counting from the left.

For example, looking for the last space using InstrRev:

Now is the Time == 11

11 is the 11th character counting from the left


How would you modify that to find the SECOND space from the right?

--




=FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-n))

where "n" is the 0-based count of spaces from the right. So for the 1st space
from the right:

=FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-0))

second space from the right:

=FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-1))

etc.


--ron



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Find Space from Right [in cell formula]



Wow that's neat.
How could you modify the formula to give
a) the position of the second-to-the-last space
b) the second-to-the-last word

--
Thanks for your reply & assistance.
Jimbo213


"Mike H" wrote:

Hi,

To find the position in the string of last space use

=LEN(A1)-LEN(RIGHT(A1,LEN(A1)-SEARCH("@",SUBSTITUTE(A1,"
","@",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))))

or if you want the last word

=MID(A1,FIND(CHAR(22),SUBSTITUTE(A1," ",CHAR(22),LEN(A1)-LEN(SUBSTITUTE(A1,"
",""))))+1,255)



Mike

"Jimbo213" wrote:


I found a Jan 5 2009 post to find the FIRST space from the right using the
InStrRev function. I'd like to incorporate this in a cell's formula, not a
VBA function.

Is that possible?

--
Thanks for your reply & assistance.
Jimbo213

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Find Space from Right [in cell formula]



Thank you Chip.
How would you modify that to find the SECOND space from the right?

--
Thanks for your reply & assistance.
Jimbo213


"Chip Pearson" wrote:

If the string to test is in A1, use the following array formula:

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

It will return the position of the last space in the text in cell A1.
If there is no space, it returns 0. If A1 is empty, you'll get a #REF
error.

Since this is an array formula, you must press CTRL SHIFT ENTER rather
than just ENTER when you first enter the formula and whenever you edit
it later. If you do this properly, Excel will display the formula
enclosed in curly braces { }. You do not type in the curly braces --
Excel inserts them automatically. For much more information about
array formulas, see www.cpearson.com/Excel/ArrayFormulas.aspx.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Thu, 25 Jun 2009 12:54:03 -0700, Jimbo213
wrote:


I found a Jan 5 2009 post to find the FIRST space from the right using the
InStrRev function. I'd like to incorporate this in a cell's formula, not a
VBA function.

Is that possible?


  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Find Space from Right [in cell formula]


On Sat, 27 Jun 2009 07:06:01 -0700, Jimbo213
wrote:

My question is how can the formula be modified to find the second space from
the right ... Now is the Time == 7 [between 'is the' ]


I thought I was pretty clear when I wrote in the message to which you
responded:

=========================
=FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-n))

where "n" is the 0-based count of spaces from the right. So for the 1st space
from the right:

=FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-0))

second space from the right:

=FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-1))
==============================

Please take a close look, especially at the last line of what I wrote
previously, and let me know what about it is not clear with regard to finding
the second space from the right.
--ron
  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Find Space from Right [in cell formula]



Ok that's clear now.
I never heard the term "0-based count " before

Thanks for your clarification.
Jimbo213


"Ron Rosenfeld" wrote:

On Sat, 27 Jun 2009 07:06:01 -0700, Jimbo213
wrote:

My question is how can the formula be modified to find the second space from
the right ... Now is the Time == 7 [between 'is the' ]


I thought I was pretty clear when I wrote in the message to which you
responded:

=========================
=FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-n))

where "n" is the 0-based count of spaces from the right. So for the 1st space
from the right:

=FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-0))

second space from the right:

=FIND(CHAR(1),SUBSTITUTE(A1," ",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-1))
==============================

Please take a close look, especially at the last line of what I wrote
previously, and let me know what about it is not clear with regard to finding
the second space from the right.
--ron

  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Find Space from Right [in cell formula]

On Mon, 29 Jun 2009 08:05:01 -0700, Jimbo213
wrote:

Ok that's clear now.
I never heard the term "0-based count " before

Thanks for your clarification.
Jimbo213


You're welcome. Glad to help. Thanks for the feedback.
--ron

-----------------------------------------------------------------------------
Our Peering Groups change
Visit : http://spacesst.com/peerin
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
Find cells with a space at the end Alain Dekker[_2_] Excel Discussion (Misc queries) 4 February 3rd 10 07:19 PM
Find last space Francis Hookham Excel Worksheet Functions 3 June 11th 07 09:36 PM
Avoiding Value error message due to space in cell w/ formula A.R. Hunt Excel Discussion (Misc queries) 3 January 26th 07 09:52 PM
Can I find and replace "white space" in a cell in Excel? biggyb75 Excel Worksheet Functions 7 July 11th 05 04:58 PM
Find last space from the right of text Myrna Larson Excel Discussion (Misc queries) 5 March 29th 05 12:15 AM


All times are GMT +1. The time now is 12:27 AM.

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

About Us

"It's about Microsoft Excel"