Thread: Help with loop
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Aaron[_17_] Aaron[_17_] is offline
external usenet poster
 
Posts: 6
Default Help with loop

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