Consulting

Results 1 to 4 of 4

Thread: Solved: Convert Cell to Hyperlink

  1. #1
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location

    Solved: Convert Cell to Hyperlink

    How do I convert a cell into Hyperlink. I've done some processing and build up my web address, the end result looks like below - location in column C ....

    http://www.transcanada.com/Alberta/r..._03_16_25.html http://www.transcanada.com/Alberta/r..._02_16_04.html http://www.transcanada.com/Alberta/r..._01_15_55.html http://www.transcanada.com/Alberta/r..._28_16_16.html http://www.transcanada.com/Alberta/r..._25_15_55.html http://www.transcanada.com/Alberta/r..._24_16_10.html
    However, they are not hyperlinked to the location, they are more or less "text".

    Instead of me clicking on the cell and copy then paste into a Web Browser, how do I convert it to an "actual" hyperlink?

    Thanks

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Try this:

    [VBA]
    Sub hyper()
    Dim i As Long, Texto As String
    For i = 1 To Range("C65536").End(xlUp).Row
    On Error Resume Next
    Texto = Range("C" & i)
    On Error GoTo 0
    ActiveSheet.Hyperlinks.Add Range("C" & i), Texto
    Next
    End Sub
    [/VBA]
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  3. #3
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    Carlos:
    Thank you, that worked really good.

  4. #4
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location
    Thanks Carlos,

    I needed a bit more flexibility, but you did put me on the right track.
    here is another take on the answer

    HTML Code:
    Sub SetHyperFormat()
    Dim lastRow As Long
    Dim firstRow As Long
    Dim myRange As Range
    Dim myString As String
    Dim myRow As Long
    
    
        lastRow = Sheet1.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        firstRow = FindStartRow 'a seperate function
        Set myRange = GetRange("ExportSeries") 'a seperate function
        
        On Error Resume Next
        For myRow = firstRow + 1 To lastRow
            myString = Trim(myRange.Cells(myRow).Value)
            If myString <> "" Then  'could add a test for a valid url here
                Application.ActiveSheet.Hyperlinks.Add myRange.Cells(myRow), myString
            End If
        Next myRow
        On Error GoTo 0
        
    Set myRange = Nothing
    End Sub
    Remember: it is the second mouse that gets the cheese.....

Posting Permissions

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