0

I have a summary sheet which I use as an index to access several sheets via a hyperlink. I'm extending it so they link directly to the appropriate row within each sheet.

I'm newish to VBA and not sure on the syntax. I'm basically trying to use the value from variable j as the row number in the cell reference. "'!A" is the first part of my cell ref in the code below. I'm then trying to concatenate the string to add j as the row number. Can this be done using the code below? I tried surrounding j with brackets, apostrophe to no avail.

For j = 2 To LastUsedRow

    link = "=Hyperlink(""#'" & (ThisWorkbook.Worksheets(i).Name) & "'!A" & j",""" & (ThisWorkbook.Worksheets(i).Name) & """)"

Many thanks

0

3 Answers 3

1

Debug.Print is your friend. This is what you get with your current code (assuming j = 1 and ThisWorkbook.Worksheets(i).Name = "Sheet1"):

=Hyperlink("#'Sheet1'!A1,"Sheet1")

The formula should look like this:

=HYPERLINK("#'Sheet2'!A1","Sheet2")

So...add just add the missing ":

link = "=HYPERLINK(""#'" & (ThisWorkbook.Worksheets(i).Name) & _
       "'!A" & j & """,""" & (ThisWorkbook.Worksheets(i).Name) & """)"
Sign up to request clarification or add additional context in comments.

Comments

1

The including of double quotes within VBA strings is tricky.

link = "=Hyperlink(""#'" & (ThisWorkbook.Worksheets(i).Name) & "'!A" & j & """,""" & (ThisWorkbook.Worksheets(i).Name) & """)"

will get link as =Hyperlink("#'SheetName'!A2","SheetName")

Comments

-1

You need to call on what you want to pull from j, such as: j.Value

3 Comments

j is an integer, it doesn't have properties.
Said who? Looks like j is a range, from 2 to LastUsedRow. So if you want to call the value of j then you do: j.value.
'Dim j As Range' 'j = 2' Let me know when that could ever work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.