Sleeper: Loop through range to copy/paste hyperlink
For all cells in a column, i need to make a hyperlink and i wrote the following macro to copy the 'display as text' property to the 'hyperlink' property (hope i'm using correct lingo). Now, I need to put this in a loop so the macro will go through the entire column and make the appropriate hyperlinks. Have tried to do simple loops (but i really have no experience w/loops in VBA) and keep getting error messages, so can someone please help??? Thanks.
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
"http://www.meditech.com/dts/srupd/Re...AR&ReqNum=9524" _
, TextToDisplay:= _
"www.meditech.com/dts/srupd/ReqDetail.asp?GO=Y&PL=MG&Appl=BAR&ReqNum=9524"
Additional code needed to run for every sheet in wkbk
:help Another complication:
This code will need to run for every sheet I have in my workbook. The column will always be the same, but how do I incorporate into the code the ability to run it on every sheet? My goal is to have a command button on the very last sheet that when clicked will run the macro for every spreadsheet in the workbook.
from where to run the code
Quote:
Originally Posted by xld
Code:
Dim sh As Worksheet
Dim iLastRow As Long
I open my workbook and run this code, but it only executes on the worksheet my cursor is on. How do I get it to execute for all sheets?:banghead:
Code:
Dim sURL As String
Dim i As Long
For Each sh In ThisWorkbook.Worksheets
With sh
iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To iLastRow
sURL = .Cells(i, "A").Value
If Left(sURL, 7) <> "http://" Then
sURL = "http://" & sURL
End If
.Hyperlinks.Add Anchor:=.Cells(i, "A"), Address:=sURL
Next i
End With
Next sh
not executing on every sheet
It's not executing on every sheet. Only the sheet the cursor happens to be on. Any way I can attach my file? I uploaded it, but don't see that it's attached so you can see it..:bug: