I am trying to create a table of contents in my spreadsheet. I have a macro that I need to read the contents of cells A1:A5 of all the sheets in the workbook and put the contents of those cells with a space starting in column B2. I am getting no errors but no information is going into the column B. Any help is appreciated.
Tom
Tom
Code:
Sub wrkbkSheetName()
Dim mainworkBook As Workbook
Dim i As Integer
Dim c As Integer
Dim x As Integer
Set mainworkBook = ActiveWorkbook
For i = 2 To mainworkBook.Sheets.Count
mainworkBook.Sheets("TableofContents").Range("A" & i) = mainworkBook.Sheets(i).Name
Next i
'Count the last cell in Column A
x = ActiveSheet.UsedRange.Rows.Count
'Select Sheet 1
Sheets("TableofContents").Select
'Select The column to start with
Range("B2").Select
For c = 2 To x
mainworkBook.Sheets("TableofContents").Range("B" & c) = mainworkBook.Sheets(c).Cells(1, 5)
Next c
End Sub