+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18

Thread: Automatic hyperlink generator with VBA

  1. #16
    Registered User
    Join Date
    10-28-2011
    Location
    Wisconsin
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Automatic hyperlink generator with VBA

    Quote Originally Posted by snb View Post
    I don't think so:

     
    Private Sub Worksheet_Change(ByVal Target As Range)
     If Target.Cells.Count > 1 Or Target.Column <> 1 Then Exit Sub
    
     On Error Resume Next
     Target.Hyperlinks.Delete
     Hyperlinks.Add Target, "", "'Data Sheet 2'!" & sheets("Data Sheet 2").Columns(5).Find(Target.Value, , xlValues, xlWhole).Address(,,,true)
    End Sub
    Thanks. I'm not sure how to handle this line from the other block of code--I get an error when using the quotation marks (assuming it sees them as the end of the statement rather than declaration of the data sheet):
    If Not f Is Nothing Then Sheets("Data Sheet 4").Hyperlinks.Add c, "", "Sheets("Data Sheet 4")!" & f.Address

  2. #17
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Automatic hyperlink generator with VBA

    Please do not quote (see the forum rules).

    With my example you must be able to do this yourself.
    It's the best way to get a 'feeling' for VBA.

    Use in the second block an approach analogous to mine:

    sub snb_4()
     On Error Resume Next  
    
     for each cl in columns(2).specialcells(2)
      Hyperlinks.Add cl, "", "#'Data Sheet 4'!" & sheets("Data Sheet 4").Columns(5).Find(cl.Value, , xlValues, xlWhole).Address
     next
    End Sub
    Last edited by snb; 11-01-2011 at 11:19 AM.



  3. #18
    Registered User
    Join Date
    10-28-2011
    Location
    Wisconsin
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Automatic hyperlink generator with VBA

    Thanks for everyone's help, I finally got it working. Here is the final code I am using:


    Sub HyperlinkSheet4ColAToSheet2ColF()
      Dim c As Range, f As Range
      Application.EnableEvents = False
      Sheets("Data Sheet 4").Range("A2", Sheets("Data Sheet 4").Range("A" & Rows.Count).End(xlUp)).Hyperlinks.Delete
      For Each c In Sheets("Data Sheet 4").Range("A2", Sheets("Data Sheet 4").Range("A" & Rows.Count).End(xlUp))
        Set f = Sheets("Data Sheet 2").Range("F2", Sheets("Data Sheet 2").Range("F" & Rows.Count).End(xlUp)).Find(c.Value)
        If Not f Is Nothing Then Sheets("Data Sheet 4").Hyperlinks.Add c, "", "'Data Sheet 2'!" & f.Address
      Next c
      Application.EnableEvents = True
    End Sub

    and



    Private Sub Worksheet_Change(ByVal Target As Range)
     If Target.Cells.Count > 1 Or Target.Column <> 1 Then Exit Sub
    
     On Error Resume Next
     Target.Hyperlinks.Delete
     Hyperlinks.Add Target, "", "'Data Sheet 2'!" & Sheets("Data Sheet 2").Columns(5).Find(Target.Value, , xlValues, xlWhole).Address(, , , True)
    End Sub

    Thanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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.2.0