+ Reply to Thread
Results 1 to 5 of 5

Using the contents of a cell to hyperlink another

Hybrid View

  1. #1
    Registered User
    Join Date
    02-28-2012
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    2

    Using the contents of a cell to hyperlink another

    I have a large index of parts. In column A I have the Part Name, and in Column H I have a location where its information can be found. I would like to write a macro that would copy the contents in Column H as the hyperlink address for Column A for the entire file.

    I have been reading and trying and tutorialing but just can't get it. Searches have also come up just a bit shy of useful information.

    Thanks for any suggestions!

    Steven
    Last edited by scatlett; 03-06-2012 at 02:21 PM.

  2. #2
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Using the contents of a cell to hyperlink another

    Make a copy of your workbook and test the code on your copy. Within a dummy workbook, I successfully passed the link contained within Column H to the text in Column A (Column A went from being text to a hyperlink of the location specified in Column H). Let me know.

    Sub CreateLinks()
    
    Dim ws         As Worksheet
    Dim rngCell    As Range
    Dim rngSource  As Range
    Dim rngDest    As Range
    Dim strLink    As String
    
       With Application
          .ScreenUpdating = False
          .EnableEvents = False
       End With
    
          Set ws = ActiveWorkbook.Sheets("Sheet1") ' Modify as applicable
             
          With ws
             lngLastRow = .Cells(.Rows.Count, "H").End(xlUp).Row
          End With
          
          Set rngSource = Range("H1", "H" & lngLastRow)
    
             For Each rngCell In rngSource
                strLink = CStr(rngCell.Value)
                Set rngDest = Range("A" & rngCell.Row)
                rngDest.Hyperlinks.Add Anchor:=rngDest, Address:=strLink
             Next
    
       With Application
          .ScreenUpdating = True
          .EnableEvents = True
       End With
    
    End Sub
    Last edited by AlvaroSiza; 03-05-2012 at 04:23 AM.
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

  3. #3
    Registered User
    Join Date
    02-28-2012
    Location
    usa
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Using the contents of a cell to hyperlink another

    That did exactly what I needed it to. Now I just need to learn how to do things like this myself.

    Thank you!

  4. #4
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Using the contents of a cell to hyperlink another

    Glad I could help. Please remember to mark your thread as solved.

    How to mark a thread solved

  5. #5
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Using the contents of a cell to hyperlink another

    Could you not just use the HYPERLINK function?
    Good luck.

+ 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