Hi,
I've been trying to figure this one out for a while now. Currently, my VBA sub has loops that read ranges and these ranges (sheets specifically) are referenced using a the sheet indexes (ex: "sheet(1)") that are looped (ex: "For intIndex = 1 To 10"). What I really want to do is loop through the sheets using the sheet codename so that if the user or I change the tab names or index number (position of tabs), it won't break the code.
This is what I am attempting but of course the method is incorrect:
I've seen others do something like what I am looking for using
"ThisWorkbook.VBProject.VBComponents("Sheet2").Name= "NewCodeName""
but I've heard that this causes errors for some and we use XP here so it may be problematic. I've also seen people setting the current sheet using a do loop and exiting the do loop when the current sheet matches what the string variable wants but this doesn't seem to be an option (I may be able to make it work if I rewrite the structure of how the code works but I would rather use the methods that are currently working).
Thanks in advance for any help you can offer.
I've been trying to figure this one out for a while now. Currently, my VBA sub has loops that read ranges and these ranges (sheets specifically) are referenced using a the sheet indexes (ex: "sheet(1)") that are looped (ex: "For intIndex = 1 To 10"). What I really want to do is loop through the sheets using the sheet codename so that if the user or I change the tab names or index number (position of tabs), it won't break the code.
This is what I am attempting but of course the method is incorrect:
Code:
Dim SheetNumber As Integer
Dim SheetCodename As String
SheetCodename = "Sheet" & SheetNumber
For SheetNumber = 1 To 10
.
.
If Workbooks(strWorkbook).SheetCodename.Range(strRColumnArray(intCurRColumnArray) & intRRow) = "X" Then
.
.
I've seen others do something like what I am looking for using
"ThisWorkbook.VBProject.VBComponents("Sheet2").Name= "NewCodeName""
but I've heard that this causes errors for some and we use XP here so it may be problematic. I've also seen people setting the current sheet using a do loop and exiting the do loop when the current sheet matches what the string variable wants but this doesn't seem to be an option (I may be able to make it work if I rewrite the structure of how the code works but I would rather use the methods that are currently working).
Thanks in advance for any help you can offer.