+ Reply to Thread
Results 1 to 11 of 11

shortening a URL

Hybrid View

  1. #1
    Registered User
    Join Date
    06-01-2007
    Posts
    9

    shortening a URL

    Hello!

    I have a very long column (almost 3000 cells) of URLs. I would like to replace them in the second column with shortened versions, basically cut them at the fourth slash.

    Let me illustrate:

    www.plant.edu/wm/mail/window/apple/seed

    would turn into

    www.plant.edu/wm/mail/window

    Could you tell me how can I used functions in Excel to do it? I am not very advanced when it comes to Excel and I need help. Thank you very much.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Does this help

    =HYPERLINK(LEFT(A1,FIND("^",SUBSTITUTE(A1,"/","^",4))-1))

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    10-10-2005
    Location
    Finland
    Posts
    10

    One solution is Macro (VBA)

    I don't see any functions to solve this. So I made little VBA-code to handle it.
    Long URLs in Column A begins with row 1. Fixed URLs will be placed in Column B. Here is the code for that. Hope it's helping you.

     Sub Shorten_URL()
    
        Dim slash_count As Integer 'counts how many slashes has been found starting from beginning of the URL
        Dim URL_rows As Integer 'Current row counter
        Dim URL_chr As Integer 'Counts characters in URL
        
        slash_count = 0
        URL_rows = 1
            
        Do Until Range("A" & Trim(Str(URL_rows))) = ""
            For URL_chr = 1 To Len(Range("A" & Trim(Str(URL_rows))))
                If Mid(Range("A" & Trim(Str(URL_rows))), URL_chr, 1) = "/" Then
                    slash_count = slash_count + 1
                End If
                If slash_count = 4 Then
                    Range("B" & Trim(URL_rows)) = Left(Range("A" & Trim(URL_rows)), URL_chr - 1)
                    slash_count = 0
                    Exit For
                End If
            Next
            URL_rows = URL_rows + 1
        Loop
    End Sub
    Last edited by VBA Noob; 06-01-2007 at 05:19 AM.

  4. #4
    Registered User
    Join Date
    06-01-2007
    Posts
    9

    Thank you

    Thank you both of you for the fast posts.

    I tried to enter the formula, VBA Noob, but it does not seem to be working. I get error message.

    I will try your solutions on Monday, Escelien. I am off work now and I want to solve the problem beginning of next week.

    Thank you very much again! It is great to see such fast responses.

  5. #5
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Here's an example

    VBA Noob
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    06-01-2007
    Posts
    9
    Thank you, VBA Noob. Unfortunately, I cannot open the file. Could you try posting it again?

  7. #7
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    If you have Windows XP, save the file to your PC and right-click on it and choose Explore. You'll then see the Excel file and can double-click to open it.

    If you don't have Windows XP, you'll need a zip utility to extract the Excel file from the .zip file (such as WinZip, WinRAR, PKZip, etc.)

+ 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