+ Reply to Thread
Results 1 to 3 of 3

InStrRev not extracting data to right of last space in string

  1. #1
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    140

    InStrRev not extracting data to right of last space in string

    Hey all, I created this macro in VBA:

    Please Login or Register  to view this content.
    This line:

    secondary_last_name = Left(main_name, InStrRev(main_name, " ") + 1)

    is supposed to extract:

    DIAZ

    in:

    ROGELIO P DIAZ

    Instead, it doesn't extract anything.


    For example in this:

    ROGELIO P DIAZ &W CLUADIA L

    This line:

    MsgBox secondary_first_name & " " & secondary_last_name

    is supposed to return this:

    CLUADIA L DIAZ

    rather it returns this:

    CLUADIA L ROGELIO P DIAZ

    Not sure why the instrrev function is not returning the data to the right of the last space in the string main_name *(e.g. ROGELIO P DIAZ) in order to extract DIAZ.

    Thanks for response.
    Last edited by johnmerlino; 06-15-2011 at 08:37 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: InStrRev not extracting data to right of last space in string

    Hi

    Your problem is caused by using pos, not pos-1 as this includes the space after
    ROGELIO P DIAZ_ (underscore used to show space)
    So, InstrRev is fining that 16th Character at the end of the main name.

    Also, uou should be using Mid not left to obtain secondary_last_name

    Please Login or Register  to view this content.
    --
    Regards
    Roger Govier
    Microsoft Excel MVP

  3. #3
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    140

    Re: InStrRev not extracting data to right of last space in string

    Thanks for response. Works well.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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