Loop through Column and add hyperlink

  • Thread starter Thread starter Smythe32
  • Start date Start date
S

Smythe32

Hi,

I am terribly bad with loops and was hoping someone could help me with
some code.

I have column A, called Item. It has numbers in it.


ex:
Item
123
124
234
223

I need to loop through all the non blank cells in the column and add a
hyperlink to each item number. They hyperlink would be something like
http:....123. The ticket number would be at the end. The main part of
the hyperlink excluding the ticket number is always the same.

Thanks for anyone who can assist.
 
The ticket number would be at the end. The main part of
the hyperlink excluding the ticket number is always the same.


Correction:

The item number would be at the end. The main part of
the hyperlink excluding the item number is always the same.
 
This will start looking at column A, row 2 and stops when it reaches the
first blank cell in column A.
The hyperlink is written into column B.

Sub HlinkPaths()
Dim i
Dim tmp
Dim myUrl
i = 2
myUrl = "http://www.google.com/" 'replace with your URL

While Range("A" & i).Value + "" <> ""
tmp = myUrl & Range("A" & i).Value

ActiveSheet.Hyperlinks.Add _
Anchor:=Range("A" & i).Offset(, 1), _
Address:=tmp, _
TextToDisplay:=tmp
i = i + 1
Wend

End Sub
 
yes, that would make sense from the question I asked. There was
actually another part that I left out. When you drill down into a pivot
table and a new sheet is created, I was putting this code in the
newsheet event because it loses the hyperlinks otherwise. Thanks for
you idea too..
 
Back
Top