+ Reply to Thread
Results 1 to 11 of 11

Trim filename from filepath using VBA with range in specific column

  1. #1
    Registered User
    Join Date
    08-31-2013
    Location
    N/A
    MS-Off Ver
    Excel 2003
    Posts
    14

    Trim filename from filepath using VBA with range in specific column

    Greetings all, I'm trying to trim a filename from a path using VBA with the filepath data located in column H. I've found and manipulated some code but cannot get this puppy to fire properly. What am I doing incorrectly and if anyone has the time to explain, why is what I have not working?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Trim filename from filepath using VBA with range in specific column

    Hi, isritter,

    for me on a PC the sign to use is \ and not /. Maybe try and use Application.PathSeparator instead of any of these hard-coded signs. And you could use InStrRev to find the last occurrance from the right.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Trim filename from filepath using VBA with range in specific column

    Hi isritter,

    Try changing the delimiter to a backslash:
    Please Login or Register  to view this content.
    Also see the following routines which help me extract parts of files:
    Please Login or Register  to view this content.
    Lewis

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Trim filename from filepath using VBA with range in specific column

    Hello isritter,

    Is your target file path a URL or local file? The delimiter for a URL is "/" while local (US) is "\".

    Can you post a sample file path?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    08-31-2013
    Location
    N/A
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Trim filename from filepath using VBA with range in specific column

    Thank you all for the replies. Leith Ross, the file path uses "/" as a separator. It's a file, not a URL that I'm after. There is a header in H1 which is text so I'm unsure if that has anything to do with it. Any ideas?

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Trim filename from filepath using VBA with range in specific column

    Hello isritter,

    I would need to see an example of the 'header".

  7. #7
    Registered User
    Join Date
    08-31-2013
    Location
    N/A
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Trim filename from filepath using VBA with range in specific column

    It might also be noteworthy to mention that I'm exporting data from another source that I'm cleaning up so the path identifies a username so it looks something like this...

    Please Login or Register  to view this content.
    I'll try and post a sample path when I get home but hopefully this sheds some light on what I'm trying to do.

    The header, located in H1 just says something like 'Username'.

  8. #8
    Registered User
    Join Date
    08-31-2013
    Location
    N/A
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Trim filename from filepath using VBA with range in specific column

    Here's the path that's listed...

    Please Login or Register  to view this content.
    The Header text, located in H1 is "Username". I'm trying to pull TomJones from the end of the path.

    I've adjusted the delimiter to turn both ways but either way, all I get is "Delimiter Not Found" in the first five cells of Column H. Thoughts?
    Last edited by isritter; 04-20-2014 at 05:00 PM.

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Trim filename from filepath using VBA with range in specific column

    Hellp isritter,

    Try this method...
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    08-31-2013
    Location
    N/A
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Trim filename from filepath using VBA with range in specific column

    That didn't work either... is it possible that the path is somehow not reading as text?

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Trim filename from filepath using VBA with range in specific column

    Hellp isritter,

    Looking at the code you posted, you are passing the string by reference (the default). The call will fail if the variable you are trying to pass has not be declared. If this fails, you should your workbook for review.
    Please Login or Register  to view this content.

+ 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. [SOLVED] Cond. formatting a column/Range, highlight cell in column/range if equal to specific text
    By DFrank231 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-19-2013, 03:35 PM
  2. [SOLVED] Copying files from a selected filepath to a filepath mentioned in a worksheet's cell
    By subbby in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-10-2012, 03:59 PM
  3. Export to HTML filename and filepath
    By magicool in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-24-2009, 05:33 PM
  4. trim range/column on particular sheet
    By JohnSeito in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-01-2007, 01:43 PM
  5. How to split filename from filepath?
    By Frank in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-04-2005, 02:05 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