Want to replace sheetname with index number

djl0525

Well-known Member
Joined
Dec 11, 2004
Messages
1,240
I have these two lines in my code.

Code:
'For c = 1 To Worksheets("[B]Exercise01[/B]").Shapes.Count
and

Code:
  Worksheets("Callouts").Range("C4").Offset(c, 0).Value = Worksheets("[B]Exercise01[/B]").Shapes(c).Name
When I change the Exercise01 sheetname, I have to edit the code.

How can I update the code to refer to sheet index 11 instead of Exercise01?

Any assistance will be greatly appreciated.

DJ
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Sheets(11) instead of Worksheets("Exercise01") but you would be better off using the sheets Codename if it is in the same workbook as the macro.
 
Upvote 0
The codename is a good idea... except that sheets are moved and copied into the file from other workbooks. I can not know the codename in advance and I want to avoid going into VBA to edit.

Are you saying, this is what I should do?

For c = 1 To Sheets(11).Shapes.Count

and

Worksheets("Callouts").Range("C4").Offset(c, 0).Value = Sheets(11).Shapes(c).Name

DJ
 
Upvote 0
Are you saying, this is what I should do?

For c = 1 To Sheets(11).Shapes.Count

and

Worksheets("Callouts").Range("C4").Offset(c, 0).Value = Sheets(11).Shapes(c).Name

DJ

If you want to use the sheets Index number then yes (btw, it is always better to test rather than ask :biggrin:).

I can not know the codename in advance

I assume then you always know the Index number in advance then.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,178
Members
449,071
Latest member
cdnMech

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