Referencing Another Worksheet Dynamically - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Referencing Another Worksheet Dynamically

turekatureka Posts: 2Member
Hey everyone I'll try and keep this short. Basically I'm trying to create a Macro that wil create a summary sheet that I can re-use multiple times and I'm having trouble referencing the cells in the other workbooks.

I've bolded the particular bit of code giving me trouble:
If x = 1 Then N = N - 1
For i = 2 To N
With Sheets("Summary Sheet")
shtName = Sheets(i).Name
'Add a hyperlink to A1 of each sheet.
.Range("B" & nRow).Hyperlinks.Add _
Anchor:=.Range("B" & nRow), Address:="#'" & _
shtName & "'!A1", TextToDisplay:=shtName
.Range("B" & nRow).HorizontalAlignment = xlLeft
.Range("A" & nRow).Value = nRow - 4
[b].Range("C" & nRow).Value = "='shtName'!$D$5"[/b]
nRow = nRow + 1
End With

If you were to click on a cell in the 'C' column I want it to read "='WhatEverThisParticularSheetsNameIs'!$D$5 . My problem is that I'm using a variable I've defined as 'shtName' instead of going through and writting in each seperate sheets name. When I include shtName in the quotes it puts it as plane text rather than using the variable.

Any help would be appreciated! Keep in mind I'm pretty bad at VBA haha.
Sign In or Register to comment.