+ Reply to Thread
Results 1 to 29 of 29

Extracting A File Name From A Path

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Extracting The Last Word Of A String

    B25 contains a formula which extract the last word of a string on A25.

    I don't understand the logic of that.
    Attached Files Attached Files

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,523

    Re: Extracting The Last Word Of A String

    It's probably best to keep to your first thread, as these queries are related: http://www.excelforum.com/excel-form...om-a-path.html
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: Extracting The Last Word Of A String

    Hi
    I use this similar formula
    Formula: copy to clipboard
    =IFERROR(MID(A25,FIND(CHAR(7),SUBSTITUTE(A25," ",CHAR(7),LEN(A25)-LEN(SUBSTITUTE(A25," ",""))))+1,255),A25)


    instead
    Formula: copy to clipboard
    =IF(ISERR(FIND(" ",A25))*LEN(A25)-LEN(SUBSTITUTE(A25," ",""))=0,A25,RIGHT(A25,LEN(A25)-FIND("*",SUBSTITUTE(A25," ","*",LEN(A25)-LEN(SUBSTITUTE(A25," ",""))))))

    to be more streamlined, although the principle is similar
    The formula use the following
    1) Count the number of spaces :: LEN(A25)-LEN(SUBSTITUTE(A25," ",""))
    2) Substitute the last space by a char not usualy used (example CHAR(7) or "*") :: SUBSTITUTE(A25," ",CHAR(7),LEN(A25)-LEN(SUBSTITUTE(A25," ","")))
    3) Locate that character (CHAR(7)) in the string :: FIND(CHAR(7),SUBSTITUTE(A25," ",CHAR(7),LEN(A25)-LEN(SUBSTITUTE(A25," ",""))))+1,255)
    4) Get the substring starting at that position :: MID(A25,FIND(CHAR(7),SUBSTITUTE(A25," ",CHAR(7),LEN(A25)-LEN(SUBSTITUTE(A25," ",""))))+1,255)
    5) On error returns the same string IFERROR(....;A25)

    Regards

  4. #4
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Extracting The Last Word Of A String

    This is a duplicate post(2ND FOR THIS SUBJECT) and as such does not comply with Rule 5 of our forum rules. As you have replies in both of your threads i'll merge these 2 threads.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  5. #5
    Forum Contributor
    Join Date
    01-16-2015
    Location
    Istanbul
    MS-Off Ver
    Office 365
    Posts
    928

    Re: Extracting The Last Word Of A String

    Isn't there a function which find the position of specified occurance of a character?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Choosing folder path (instead of file path) in VBA
    By sminter in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-23-2014, 08:50 PM
  2. Specified folder path to select file path
    By JayEmTee91 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-29-2012, 10:38 AM
  3. Extracting the folder name and filename from a file path?
    By Skywalker in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-25-2012, 08:17 PM
  4. Extracting a file path from a cell in VBA
    By ChromiumAgeCollector in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-30-2012, 10:08 AM
  5. Extracting File Path from Application.GetOpenFile
    By Retec123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-25-2010, 06:28 PM
  6. Replies: 7
    Last Post: 10-09-2009, 10:10 AM
  7. Use String Variables in File Path and create path if not existing
    By JanBang in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-26-2007, 09:04 AM

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