Solved

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

Posted on 2011-02-25
6
692 Views
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.
ie.

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.
0
Comment
Question by:CMWinters
  • 3
  • 2
6 Comments
 
LVL 11

Assisted Solution

by:dougaug
dougaug earned 83 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:
=CreateHyperlink("http://server/page.aspx?iid=";A1)
0
 
LVL 81

Accepted Solution

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

=HYPERLINK("http://server/page.aspx?iid="&A1)

Kevin
0
 
LVL 30

Assisted Solution

by:SiddharthRout
SiddharthRout earned 166 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
    Else
        MsgBox "Not Found"
    End If
End Sub

Open in new window


Sid
hyperlink-example.xls
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 30

Assisted Solution

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

Sid
0
 
LVL 81

Assisted Solution

by:zorvek (Kevin Jones)
zorvek (Kevin Jones) earned 251 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:

=HYPERLINK("http://server/page.aspx?iid="&A2,A2)

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

Kevin
0
 
LVL 81

Assisted Solution

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

Kevin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

912 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now