I want to create a very basic table of contents sheet at the beginning of my workbook. Count the sheets, loop thru each sheet recording the tab name in an array. Go to the TOC sheet and write that tab names in column A. That's all; very simple. NOT.
I'm sure there's a better way to write to the TOC sheet, but for now my problem is that I'm not getting anything in my tabnames array!!! Have tried tabnames(ai).value=, tabnames(ai).formula=, etc. I keep getting "TOC" written 15 times on the TOC sheet.
Also, how to dim the array for an unknown number of tabs???
Any help is most appreciated. I'm sure it's something simple, but I'm in a downward mental spiral by now.
Thanks,
Deb
Sub tableofcontents()
Dim i As Integer, ai As Integer
Dim tabnames(1 To 1000) As String
i = Worksheets.Count
For i = 2 To Worksheets.Count
ai = i - 1
Sheets(i).Activate
tabnames(ai) = "=RIGHT(CELL(""filename"",R1C1),LEN(CELL(""filename"",R1C1))-FIND(""]"",CELL(""filename"",R1C1)))"
Next i
For i = 1 To Worksheets.Count - 1
Sheets("TOC").Activate
Cells(i, 1).Value = tabnames(i)
Next i
End Sub
I'm sure there's a better way to write to the TOC sheet, but for now my problem is that I'm not getting anything in my tabnames array!!! Have tried tabnames(ai).value=, tabnames(ai).formula=, etc. I keep getting "TOC" written 15 times on the TOC sheet.
Also, how to dim the array for an unknown number of tabs???
Any help is most appreciated. I'm sure it's something simple, but I'm in a downward mental spiral by now.
Thanks,
Deb
Sub tableofcontents()
Dim i As Integer, ai As Integer
Dim tabnames(1 To 1000) As String
i = Worksheets.Count
For i = 2 To Worksheets.Count
ai = i - 1
Sheets(i).Activate
tabnames(ai) = "=RIGHT(CELL(""filename"",R1C1),LEN(CELL(""filename"",R1C1))-FIND(""]"",CELL(""filename"",R1C1)))"
Next i
For i = 1 To Worksheets.Count - 1
Sheets("TOC").Activate
Cells(i, 1).Value = tabnames(i)
Next i
End Sub