Help with loop

A

Aaron

I'm not getting the desired result with this loop:

A1 = hello
A2 = goodbye
A3 = hello again

when I run this macro with cells A1-A2 selected, the resulting
hyperlink is http://www.google.com/search?&q=goodbye for all selected
cells.

When I run the macro with A3 selected, it breaks with an error.

Sub makelink()
Dim Cell As Range
For Each Cell In Intersect(Selection, ActiveSheet.UsedRange)
If Cell <> "" Then
Dim sLinkAddress As String
sLinkAddress = "http://www.google.com/search?&q= & Chr(34) &
Cell.Value & Chr(34)
ActiveSheet.Hyperlinks.Add Anchor:=Selection,
Address:=sLinkAddress
Exit For
End If
Next
End Sub
 

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