PDA

View Full Version : [SOLVED:] Question on Hpyerlink



willhh3
01-28-2011, 06:47 PM
I need to figure out how to create a hyperlink using a column of numbers. I want to make each number into a hyperlink and tack on the number at the end.
Example (plain text):
a
1 45678
2 55543
3 78945
4 85664
So when I’m done I’d like the cell to display the same numbers as above, but the hyperlink would look like this:

a
1 http://ABCompany.com/billing/view.aspx?id=45678
2 http://ABCompany.com/billing/view.aspx?id=55543
3 http://ABCompany.com/billing/view.aspx?id=78945
4 http://ABCompany.com/billing/view.aspx?id=85664

So again the numbers would remain as they are but be hyerlinks combining "http://ABCompany.com/billing/view.aspx?id=" with whatever number is in the cell. I'd like this to loop down to the last cell with data.

Here is the code I have been trying to get to work, but not quite there. I can get the hpyerlink to work for a range of cells, but not to loop down to the last cell. I'm also open to a different, cleaner approach.


Dim CR_Num As String
CR_Num = ActiveCell.Value
Range("A1").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
"http://ABCompany.com/billing/view.aspx?id=" & ID_Num
ActiveCell.Value = CR_Num

So in a nutshell I want to take "http://abcompany.com/billing/view.aspx?id=", add the value of the cell to the end and make it a hyperlink with the cell only displaying the orginal number.

Thanks in advanced and sample file attached.
Whh

Kenneth Hobs
01-28-2011, 07:37 PM
Sub SetHyperlinks()
Dim linkRange As Range, cell As Range
Set linkRange = Range("A3", Range("A" & Rows.Count).End(xlUp))
For Each cell In linkRange
ActiveSheet.Hyperlinks.Add Anchor:=cell, Address:= _
"http://ABCompany.com/billing/view.aspx?id=" & cell.Value
Next cell
End Sub

willhh3
01-28-2011, 07:55 PM
Perfect! Thank you!