Add loop to Macro

AinaRF

New Member
Joined
Apr 19, 2018
Messages
3
Hi,
I'm completely new to using macros/VBA. I've been already looking through several posts/forums/tutorials but so far I haven't succeeded. I've found similar posts, but I haven't managed to apply it to my case.

In Excel I've got a very long column (approx. 16000 cells) containing web addresses, I would like to convert all those into hyperlinks without having to do it one by one. (so that I can click on the cell and be directed to the webpage)
I've got the macro for one single cell but I would like to apply it to the entire column. Any help on how and where I need to place the loop will be GREATLY appreciated.

Sub hipervinculo()

ActiveSheet.Hyperlinks.Add anchor:=ActiveCell, Address:=ActiveCellValue, SubAddress:=""

End Sub

Thanks a lot!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Welcome to the board.

Adjust variable y for the column number your data is in then try:
Rich (BB code):
Sub hipervinculo()

    Dim x   As Long
    Dim start_row   As Long
    Dim y   As Long
    Dim LR  As Long

    start_row = 1 'Row your hyperlinks start in, adjust as needed
    y = 10 'this assumes your hyperlinks are in column J, change 10 to suit

    Application.ScreenUpdating = False

    With ActiveSheet
        'Row number of last used cell in column number y
        LR = .Cells(.Rows.Count, y).End(xlUp).Row
        For x = start_row To LR
            .Hyperlinks.Add anchor:=.Cells(x, y), Address:=.Cells(x, y).Value, SubAddress:=""
        Next x
    End With
    
    Application.ScreenUpdating = True

End Sub
 
Last edited:
Upvote 0
Welcome to the board.

Adjust variable y for the column number your data is in then try:
Rich (BB code):
Sub hipervinculo()

    Dim x   As Long
    Dim start_row   As Long
    Dim y   As Long
    Dim LR  As Long

    start_row = 1 'Row your hyperlinks start in, adjust as needed
    y = 10 'this assumes your hyperlinks are in column J, change 10 to suit

    Application.ScreenUpdating = False

    With ActiveSheet
        'Row number of last used cell in column number y
        LR = .Cells(.Rows.Count, y).End(xlUp).Row
        For x = start_row To LR
            .Hyperlinks.Add anchor:=.Cells(x, y), Address:=.Cells(x, y).Value, SubAddress:=""
        Next x
    End With
    
    Application.ScreenUpdating = True

End Sub

You guys rock!
Thanks a mil! It worked! I spent all day yesterday trying to figure it out...I know it's simple if you know how to use VBA but for those of us who don't...it's rather nightmarish :)
Thanks again!!
 
Upvote 0
You're welcome Aina :)

For future posts, just assume anyone reading cannot see your screen(!), being precise (e.g. giving sheet names, column letters, cell addresses etc) helps suggest a solution that is more precise without guesswork or needing to extend thread by needing to ask for these details.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top