Reputation:
I need to copy the worksheets name into Row 1 of another worksheet of the same file. Here is what I have/need:
Can you help me? :)
Upvotes: 1
Views: 850
Reputation: 54807
Sub ListNames()
Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code
Dim dCell As Range: Set dCell = wb.Worksheets(2).Range("B1")
Dim n As Long
For n = 3 To wb.Worksheets.Count
dCell.Value = wb.Worksheets(n).Name
Set dCell = dCell.Offset(, 1)
Next n
End Sub
Upvotes: 3
Reputation: 10236
From what you write it's really hard to tell what you actually need.
The following VBA code writes the name of the 3rd worksheet to the B1
cell of sheet 2. If you don't have 3 sheet's nothing happens:
Sub WriteTheNameOfWorksheet3IntoWorksheet2CellB1()
If ActiveWorkbook.Worksheets.Count >= 3 Then
ActiveWorkbook.Worksheets(2).Range("B1") = ActiveWorkbook.Worksheets(3).Name
End If
End Sub
Upvotes: 1