Consulting

Results 1 to 5 of 5

Thread: delete characters from string

  1. #1
    VBAX Newbie
    Joined
    Oct 2015
    Posts
    2
    Location

    delete characters from string

    Dear all,

    For example I have a string like:

    C:/users/library/music/mp3/this-song.mp3

    In my sheet I create a hyperlink with that path but I also need to create a hyperlink to the folder of the file.

    I tried this:

    =LEFT(C:/users/library/music/mp3/this-song.mp3,FIND(C:/users/library/music/mp3/this-song.mp3,"/")
    This code gives me C: because the find function finds the first / How can I change the code so that it will keep searching the string for / and take all the chars left of the last one and the last / included.

    I do something wrong, please help.

    Kind regards,

    Wizard0

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    InStrRev() is your friend



    Option Explicit
    Sub Demo()
        Dim i As Long
        Dim s As String, s1 As String
        
        s = "C:/users/library/music/mp3/this-song.mp3"
        
        i = InStrRev(s, "/")
        
        s1 = Left(s, i - 1)
        MsgBox s1
    
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    Use 'basename' of the scripting library:

    see:

    http://www.snb-vba.eu/VBA_Bestanden.html#L_2


    of

    =LEFT(C:/users/library/music/mp3/this-song.mp3,FIND(C:/users/library/music/mp3/this-song.mp3,".")-1)
    Last edited by snb; 10-07-2015 at 02:48 PM.

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    if you need a worksheet formula rether than vba:

    http://www.mrexcel.com/forum/excel-q...v-excel-2.html

    posts 12 and 13.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    This thread demonstrates what makes VBA Express the best integrated Microsoft Office site in the web.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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