looping hyperlink

BrendanDixon

Board Regular
Joined
Mar 7, 2010
Messages
174
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi all I have

200 cells that I want to add hyperlinks to different sheet. I am trying to run a loop where I can fill in these automatically....

basically I want Cell E203 to hyperlink to sheet 201!A1
Cell E204 to hyperlink to sheet 202!A1
Cell E205 to hyperlink to sheet 203!A1 etc

all the way to 400. This is what I have written so far but it comes up with an error and I do not know the syntax to do the range with a counting number
Code:
Sub test()
Dim i As Long, Got As Boolean
            For i = 202 To 400
Range(E(i)).Select
    ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
        "'(i-2)'!A1", TextToDisplay:="View"
    Next i
   
End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
This works but I'm not sure if the references are exactly right - it worked with the few sheets I created.
Code:
Dim ws As Worksheet
Dim rng As Range
Dim I As Long
 
    Set ws = Worksheets("Sheet1")
 
    For I = 203 To 400
 
        Set rng = ws.Range("E" & I)
 
        rng.Hyperlinks.Add Anchor:=rng, Address:="", SubAddress:="Sheet" & I - 2 & "!A1", TextToDisplay:="Sheet" & I - 2 & "!A1"

    Next I
 
Upvote 0

Forum statistics

Threads
1,224,531
Messages
6,179,384
Members
452,908
Latest member
MTDelphis

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