Loop through Column and add hyperlink

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.
 
S

Smythe32

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.
 
S

Steve

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
 
S

Smythe32

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..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top