0
votes

How can I select worksheet in excel using vba even when sheet name and sheet position changed constantly?

I was using sheet index to avoid vba fail to select worksheet after changing the worksheet name, however, if I change relative position of the ws, its index changes.

I noticed that sheet name in vba project browser, there is a item called (name) which is a fixed sheet number (I guess it was named by the sequence that I created the ws.) Is it possible to select ws based on this fixed name?

Thank you

1
"Is it possible to select ws based on this fixed name?" Yes, you are referring to the sheet codename. - BigBen
Thank you, it was confusing as I initially thought sheet index should be fixed and same as the codename - Tak Chan

1 Answers

2
votes

You can use Name in VBE to specify your name for Worksheet. This will allow you to rename your Worksheet in Excel according to your needs.

In VBA you can then use something like:

Option Explicit

Sub Test()

MyWorksheetName.Activate

End Sub

This is where you edit your Name:

enter image description here