Multiple hyperlinks via macro?

  • Thread starter Thread starter Ron
  • Start date Start date
R

Ron

Help please for adding hyperlinks with a macro.

The result of a macro recording session using only one cell AI is
below

Range("A1").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
"2004/Backups/040110.xls", TextToDisplay:= _
"Lusc.......   "

How can I hyperlink multiple cells beginning in A1 and then in every
odd row number in Col A?

eg.
A

1. Lusc...  
2. Occu..
3. Boun...
4. Savo...
5. Pana...
6. Sail...

The total number of rows varies each time the macro runs.

TIA

Ron
 
Option Explicit
Sub testme01()

Dim FirstRow As Long
Dim LastRow As Long
Dim iRow As Long

With ActiveSheet
FirstRow = 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = FirstRow To LastRow Step 2
.Hyperlinks.Add Anchor:=.Cells(iRow, "A"), _
Address:="2004/Backups/040110.xls", _
TextToDisplay:="Lusc....... "
Next iRow
End With
End Sub

But I'm not sure what goes in the address and texttodisplay parms.

You can use:
.cells(irow,"A").value
to retrieve the text in the cell if you want.
 
Ron,

Sub testit()
Dim i As Long, lngLastRow As Long

With Sheet1
lngLastRow = .Cells(1, 1).End(xlDown).Row
For i = 1 To lngLastRow
.Hyperlinks.Add .Cells(i, 1), "2004/Backups/040110.xls", , ,
..Cells(i, 1)
Next
End With
End Sub

Rob
 
Dave,

For the address and text used

Address:="2004/Backups/040110.xls", _
TextToDisplay:=.Cells(iRow, "A").Value

Worked exactly as required.

Thank you and best wishes

Ron

 

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

Back
Top