How to link cells to Sheet names using a for loop

bellg

New Member
Joined
May 13, 2014
Messages
29
I'm trying to write some code that links to certain sheets if certain cells are clicked. My sheets are named "01", "02", "03", ... , "20", ... "XX". I'm hoping I can use some loops to reference the names of the sheets since they are in a number format, but "j", which is how I tried to link cell rows with a corresponding sheet, in the code below doesn't cooperate. Can anyone help me fix this or can you simply not reference sheet names this way?

If ActiveCell.Column = 4 Or 5 Then
For i = 5 To 7
j = i - 4
If ActiveCell.Row = i Then
Sheets("0j").Activate
Exit Sub
Else
End If
Next
Else
End If
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
If you put a variable inside of the quotes it gets viewed as a literal string. You can put the variable outside the quote like this:

Code:
Sheets("0" & j).Activate
 
Upvote 0

Forum statistics

Threads
1,215,489
Messages
6,125,093
Members
449,205
Latest member
ralemanygarcia

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