Find character counting from the right

Sheridi

Board Regular
Joined
Nov 20, 2015
Messages
76
I know I've seen this done but for the life of me can't figure it out.

I want to find the first space in a text string (in a cell) counting from the right.

ie.... in Cell A1 I have "now is the time"

I want a formula to tell me that the first space from the right is at position 5.

Thanks!
 
Perhaps

Code:
Function LastSpaceFromRight(aString As String) As Long
    LastSpaceFromRight = 1 + Len(Split(StrReverse(aString), " ")(0))
End Function
Returns the length of the string if that string contains no spaces. Also returns #VALUE! error for a blank cell. My code did the same thing before I put the If..Then test that I used in front of it. As an aside, the InStrRev function call I used is more efficient than your Split(StrReverse combination.
 
Last edited:
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,215,262
Messages
6,123,953
Members
449,135
Latest member
jcschafer209

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top