Results 1 to 5 of 5

Thread: Hyperlink Range

  1. #1
    2 Star Lounger
    Join Date
    Apr 2015
    Posts
    153
    Thanks
    70
    Thanked 0 Times in 0 Posts

    Hyperlink Range

    Hi Experts,

    The attached file contains code to hyperlink a range of cells. It only works part of the way. What's up. I haven't been able to figure out how to make it work properly.

    Thanks in advance.
    Attached Files Attached Files

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,435
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    E.N.,

    Kind of hard to debug code if you don't know what you are trying to accomplish.

    But from what I can see maybe this is what you're after.
    You need to run your loop backwards (row n to row 1) since your starting point is the last row.

    Code:
    Private Sub Workbook_Open()
    
        Dim LastRow As Long
        Dim i       As Long
        
        LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
        For i = LastRow To 1 Step -1
           If Cells(i, 13).Value <> "" Then
             ActiveSheet.Hyperlinks.Add Anchor:=Cells(i, 1), Address:=Cells(i, 13).Value
           End If
        Next i
        
    End Sub
    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. The Following User Says Thank You to RetiredGeek For This Useful Post:

    Excelnewbie (2016-06-04)

  4. #3
    2 Star Lounger
    Join Date
    Apr 2015
    Posts
    153
    Thanks
    70
    Thanked 0 Times in 0 Posts
    RG,

    You're right. I neglected to provide details.

    I'm working on making hyperlinks for websites using column M. If there is data in column A and the cell in column M isn't empty, then make the link clickable.

    I will be using the links in a label on a form.

    Thanks for your help.
    Last edited by Excelnewbie; 2016-06-04 at 20:41.

  5. #4
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,435
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    EN,

    Ok, I think this is what you want:
    Code:
    Option Explicit
    
    Private Sub Workbook_Open()
    
        Dim LastRow As Long
        Dim lCurRow As Long
        
        LastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
        For lCurRow = LastRow To 1 Step -1
           If ((Cells(lCurRow, 1).Value <> "") And _
               (Cells(lCurRow, 13).Value <> "")) Then
             ActiveSheet.Hyperlinks.Add Anchor:=Cells(lCurRow, 13), _
                  Address:=Cells(lCurRow, 13).Value
           End If
        Next lCurRow
        
    End Sub
    Results:
    ENHyper.PNG

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  6. The Following User Says Thank You to RetiredGeek For This Useful Post:

    Excelnewbie (2016-06-04)

  7. #5
    2 Star Lounger
    Join Date
    Apr 2015
    Posts
    153
    Thanks
    70
    Thanked 0 Times in 0 Posts
    RG,

    Thanks be to you, again. Works as advertised!

    It helped!

Posting Permissions

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