+ Reply to Thread
Results 1 to 9 of 9

Creating a hyperlink with a macro

Hybrid View

  1. #1
    Registered User
    Join Date
    11-17-2007
    Posts
    5

    Creating a hyperlink with a macro

    Hi all,

    I would like your help in creating a hyperlink in a sheet, pointing from the selected cell to a different cell in the same sheet.

    The user is supposed to select a cell, and activate the macro.
    The macro should pop up an inputbox to allow the user to select (point) a different cell in the sheet.
    The macro should then create a hyperlink to this cell.

    The cell will usually contain a Dollar value, and the target cell will usually contain a name of a part.

    If possible, I would also like the macro to show, in the cell adjacent to the cell that contains the link, the value of the target cell. For example, the user will see in the linked cell a certain Dollar value (i.e. $1000) and next to it, he will see the value of the linked/target cell (i.e. the part's name).

    I have tried and tried but never succeeded in doing that… even when I managed to create a link, it didn't work (I received an error message stating that there is an invalid reference).

    Your help will be highly appreciated.

    Regards,

    Dror

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,486
    Hi,
    Let's see what you have so far, and go one step at a time.
    Zip an copy of what you have and attach it to your next post,so somebody will be able to look at it

  3. #3
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    Try this:
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim IB As String
    If Target.Row = 1 Then Exit Sub
            If Target.Cells.Count > 1 Then Exit Sub
                If Target.NumberFormat = "[$$-409]#,##0.00" Then
                IB = InputBox("Enter Destination Cell In This Format A1", "Hyperlink Destination", "Type Here")
        ActiveSheet.Hyperlinks.Add Anchor:=Target.Offset(0, 1), Address:="", SubAddress:= _
            "" & IB, TextToDisplay:=Range(IB).Text
                    Else: Exit Sub
                End If
    End Sub
    EDITED AS PREVIOUS CODE DIDN'T WORK CODE ABOVE WORKS FINE!
    Last edited by Simon Lloyd; 11-17-2007 at 01:38 PM.
    Not all forums are the same - seek and you shall find

  4. #4
    Registered User
    Join Date
    11-17-2007
    Posts
    5

    Here is a sample file

    Simon, thanks for the code but I can't get it to work.

    Attached is a sample of the file as i need it to look (it is just a rough format and will change for sure...).
    In any case, you can see "my" macro (which does not work) as well as Simon's macro (in sheet1).

    Thanks for your time,

    Dror
    Attached Files Attached Files

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Dror,

    This macro uses the ActiveCell's text as the text for the Hyperlink. The Hyperlink will go to any cell on any Worksheet the user chooses with the InputBox.
    Sub Link2Cell()
    
      Dim LinkCell As Range
      
        Set LinkCell = Application.InputBox( _
            Prompt:=Prompt, _
            Title:=Title, _
            Default:=ActiveCell.Address, _
            Type:=8)
        
        SubAddx = LinkCell.Parent.Name & "!" & LinkCell.Address
        LinkCell.Hyperlinks.Add Anchor:=ActiveCell, Address:="", _
                                SubAddress:=SubAddx, _
                                TextToDisplay:=ActiveCell.Text
          
    End Sub
    Sincerely,
    Leith Ross

  6. #6
    Registered User
    Join Date
    11-17-2007
    Posts
    5

    Thumbs up

    Works like a charm.
    Thank you all for your help!

+ 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