Thread: Reverse find
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default Reverse find

On Sat, 22 Jul 2006 21:22:25 -0400, Ron Rosenfeld
wrote:

On Sat, 22 Jul 2006 21:13:29 -0400, cooldyood
wrote:


Is there a built-in function to find the last space in a string? In
other words, I want to search within a string from right to left.


Number of Last Space:

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


--ron


I overlooked that this is the Programming group. The VBA function you want is
InStrRev.

==============================
Option Explicit

Sub LastSpace()
Const sTestString As String = "This is a Test"
Dim lLastSpace As Long
Const sSpace As String = " "

lLastSpace = InStrRev(sTestString, sSpace)

Debug.Print "The Last Space is at location " & lLastSpace

End Sub
===============================
The Last Space is at location 10
-----------------------------------


--ron