excel vba to embed a hyperlink within a cell based on the cell's value

Posted on 2011-02-25
Medium Priority
Last Modified: 2012-05-11
I would like to embed a hyperlink into a cell where the ending of the cell is part of the link.

Cell value is [ticket number] the url is "http://server/page.aspx?iid=[ticket number]

i then have a button that copies all cells and pastes them as 'value' and e-mails it to my director.

any help you could provide would be appreciated.
Question by:CMWinters
  • 3
  • 2
LVL 11

Assisted Solution

dougaug earned 332 total points
ID: 34983884
Insert a new module in your workbook and add the following function:

Function CreateHyperlink(URL As String, aCell As Range) As String
  CreateHiperlink = URL + aCell.Text
End Function

In your worksheet, add the following formula in a cell:
LVL 81

Accepted Solution

zorvek (Kevin Jones) earned 1004 total points
ID: 34983926
You don't need VBA. Use the HYPERLINK function:


LVL 30

Assisted Solution

SiddharthRout earned 664 total points
ID: 34983942
Is this what you are trying?

Sample File Attached

Code Used

Private Sub CommandButton1_Click()
    Dim aCell As Range
    Dim strURL As String, MyArray() As String
    strURL = "http://server/page.aspx?iid=4"
    MyArray = Split(strURL, "=")
    strSearch = Trim(MyArray(1))
    MsgBox strSearch
    Set aCell = Sheets("Sheet1").Columns(1).Find(What:=strSearch, LookIn:=xlValues, _
    LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)
    If Not aCell Is Nothing Then
        Sheets("Sheet1").Hyperlinks.Add Anchor:=aCell, Address:=strURL
        MsgBox "Not Found"
    End If
End Sub

Open in new window

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LVL 30

Assisted Solution

SiddharthRout earned 664 total points
ID: 34983950
Sorry. Remove Line 10 from the above code.

LVL 81

Assisted Solution

by:zorvek (Kevin Jones)
zorvek (Kevin Jones) earned 1004 total points
ID: 34983955
A caveat: The ticket number has to be in a separate cell.

I would implement it like this:

Put the ticket number in column A. In column B use this formula:


This will create the hyperlink in column B and display the ticket number.

LVL 81

Assisted Solution

by:zorvek (Kevin Jones)
zorvek (Kevin Jones) earned 1004 total points
ID: 34983970
Then hide column A so that only column B is visible as ticket numbers that link to a web page.


Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question