How do i increment a sheets 'codename' so that it can be referenced?
Sheet 'codename' - (quoted from - Using sheet codenames in Microsoft Excel VBA - )'
if a user subsequently modified the tab name again - to "JanSales", for instance - then the existing code would generate a run-time error as VBA would not be able to find the sheet.
In order to avoid this common problem, you can use the sheet's codename (the codename is the part that remained as Sheet1 in the two examples above) in your VBA code, as shown below:
Sheet1.Select'
--
As part of what i'm trying to achieve is, I import a number of CSV files that when imported rename the 'TAB Names' so the order and name will always change, this is why i need to use the sheets 'codename'.
I need to run a number of different SUBs to do different jobs with the data but to begin with i need to retrieve some information and put it into a sheet called 'TOTALS',
My previous code worked fine but fell over when the tab names went dynamic,
so i assumed that 'sheet & a' would work but it doesnt and as i use the 'sheet' reference in many other places can sheet 'codename' still work in those other places?
Thanks,
Sheet 'codename' - (quoted from - Using sheet codenames in Microsoft Excel VBA - )'
if a user subsequently modified the tab name again - to "JanSales", for instance - then the existing code would generate a run-time error as VBA would not be able to find the sheet.
In order to avoid this common problem, you can use the sheet's codename (the codename is the part that remained as Sheet1 in the two examples above) in your VBA code, as shown below:
Sheet1.Select'
--
As part of what i'm trying to achieve is, I import a number of CSV files that when imported rename the 'TAB Names' so the order and name will always change, this is why i need to use the sheets 'codename'.
I need to run a number of different SUBs to do different jobs with the data but to begin with i need to retrieve some information and put it into a sheet called 'TOTALS',
My previous code worked fine but fell over when the tab names went dynamic,
VBA Code:
Sheets("Totals").Cells(a, 1).Value = Sheet & a.Cells(a, 1).Value
' Sheets("Totals").Cells(a, 1).Value = Sheets("sheet" & a).Cells(a, 1).Value
Sheets("Totals").Cells(a, 2).Value = Sheets("sheet" & a).Cells(a, 2).Value
Sheets("totals").Cells(a, 4).Value = WorksheetFunction.Sum(Worksheets("sheet" & a).Range(Worksheets("sheet" & a).Cells(2, 3), Worksheets("sheet" & a).Cells(999, 3)))
Sheets("totals").Cells(a, 3).Value = WorksheetFunction.CountA(Worksheets("sheet" & a).Range(Worksheets("sheet" & a).Cells(2, 4), Worksheets("sheet" & a).Cells(999, 4)))
a = a + 1
Loop
Thanks,