+ Reply to Thread
Results 1 to 4 of 4

Reverse find

  1. #1
    Registered User
    Join Date
    06-20-2006
    Posts
    15

    Reverse find

    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.

  2. #2
    Ron Rosenfeld
    Guest

    Re: Reverse find

    On Sat, 22 Jul 2006 21:13:29 -0400, cooldyood
    <[email protected]> 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

  3. #3
    Bob Flanagan
    Guest

    Re: Reverse find

    untested:

    anyS ="cell.value
    for I = len(anyS) to 1 step -1
    if mid(anys, i,1) = " " then
    msgbox "last space found"
    exit for
    end if
    next

    Bob Flanagan
    Macro Systems
    144 Dewberry Drive
    Hockessin, Delaware, U.S. 19707

    Phone: 302-234-9857, cell 302-584-1771
    http://www.add-ins.com
    Productivity add-ins and downloadable books on VB macros for Excel

    "cooldyood" <[email protected]> wrote
    in message news:[email protected]...
    >
    > 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.
    >
    >
    > --
    > cooldyood
    > ------------------------------------------------------------------------
    > cooldyood's Profile:
    > http://www.excelforum.com/member.php...o&userid=35611
    > View this thread: http://www.excelforum.com/showthread...hreadid=564043
    >




  4. #4
    Ron Rosenfeld
    Guest

    Re: Reverse find

    On Sat, 22 Jul 2006 21:22:25 -0400, Ron Rosenfeld <[email protected]>
    wrote:

    >On Sat, 22 Jul 2006 21:13:29 -0400, cooldyood
    ><[email protected]> 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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1