Consulting

Results 1 to 7 of 7

Thread: Solved: Getting Hyperlink from cell

  1. #1
    VBAX Contributor
    Joined
    Apr 2006
    Posts
    100
    Location

    Solved: Getting Hyperlink from cell

    I need help with getting the hyperlink address from Column A and making a text value in Column C

    [VBA]Option Explicit
    Sub findALink()
    Dim strcell As String
    Dim i As Long
    Dim iLastRow As Long
    With ActiveSheet
    iLastRow = Cells(Rows.Count, "A").End(xlUp).Row

    For i = 1 To iLastRow
    strcell = "C" + Trim(Str(i))
    If Range(strcell).Value = "" Then

    .Cells(i, "C").Value = .Cells(i, "A").Hyperlinks.Address

    End If

    Next i
    End With
    End Sub[/VBA]

    Thanks

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I'm not clear of your code function, but here's the basic syntax
    [vba] hAdd = ActiveSheet.Name & "!A" & i
    .Cells(i, "C").Hyperlinks.Add Anchor:=.Cells(i, "C"), Address:="", SubAddress:= _
    hAdd, TextToDisplay:=hAdd[/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Contributor
    Joined
    Apr 2006
    Posts
    100
    Location
    Sorry I was tired and in a rush. I have in Column "A" a word that is hyperlinked to somewhere on our intranet. So in column "C" if that cell is blank then take the hyperlink address of the cell in column "A" and add it the cell of column "C" as text only.

    So if A3 cell is book1 with hyperlink of

    http://www.cnn.com


    So C3 should say this

    http://www.cnn.com

    Just text only no hyperlinked.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Option Explicit
    Sub findALink()
    Dim strcell As String
    Dim i As Long
    Dim iLastRow As Long
    With ActiveSheet
    iLastRow = Cells(Rows.Count, "A").End(xlUp).Row

    For i = 1 To iLastRow
    strcell = "C" + Trim(Str(i))
    If Range(strcell).Value = "" Then

    On Error Resume Next
    .Cells(i, "C").Value = .Cells(i, "A").Hyperlinks(1).Address
    On Error Goto 0
    End If
    Next i
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Here is a way to check the links

    [VBA]Sub HLinks1()

    For Each cell1 In Range("A:A").Hyperlinks
    Range("C" & CStr(cell1.Range.Row)).Value = cell1.Range.Value
    Next cell1

    End Sub
    [/VBA]

  6. #6
    VBAX Contributor
    Joined
    Apr 2006
    Posts
    100
    Location
    Thanks xld that did the trick. I going to run some test today with your code and other code that I have, and if all goes well I will mark this thread as solved after I finish this project.

  7. #7
    VBAX Contributor
    Joined
    Apr 2006
    Posts
    100
    Location
    Got it working and thanks everyone

Posting Permissions

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