Copy Worksheet Name for every sheet in workbook and paste in master sheet

xceln00b

New Member
Joined
Aug 30, 2016
Messages
5
Excel vba noob here,
I have 10 sheets in a workbook, I want my code to create a new sheet called "Master"; and for each sheet in the workbook, I want the sheet name in the cell A2, A3 , A4 etc in the "Master" sheet.

I want the output to look like the below for the "Master" sheet:
Cell A2 - Sheet1 Name
Cell A3 - Sheet2 Name
Cell A4 - Sheet3 Name

... and so on

The code i have so far is

Code:
Sub CopyIt()

Dim ws As Worksheet, x As Long


Application.ScreenUpdating = False


Worksheets.Add.Name = "Master"
Sheets("Master").Range("A1").Value = "Associate Name"


    For Each ws In ActiveWorkbook.Worksheets
        If ws.Name <> "Master" Then
            x = x + 1
            ws.Name.Copy 'This is where the code is going wrong. I think i need to fix it here somehow.
            Sheets("Master").Range("A1").Offset(x).PasteSpecial xlPasteValues
            
        End If
    Next


Columns.AutoFit


Application.ScreenUpdating = True


End Sub



I figured it's probably a piece of cake for you pros :)

Your help is much appreciated!!
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
You are close, but you don't want the copy bit. Try this instead:
Code:
Sub CopyIt()
Dim ws As Worksheet, x As Long
Application.ScreenUpdating = False
On Error Resume Next  'In case sheet Master already exists
Application.DisplayAlerts = False
Worksheets("Master").Delete
On Error GoTo 0
Worksheets.Add.Name = "Master"
Sheets("Master").Range("A1").Value = "Associate Name"
For Each ws In ActiveWorkbook.Worksheets
    If ws.Name <> "Master" Then
        x = x + 1
        Sheets("Master").Range("A1").Offset(x) = ws.Name
    End If
Next ws
Columns("A").AutoFit
With Application
    .ScreenUpdating = True
    .DisplayAlerts = True
End With
End Sub
 
Upvote 0
omg. WOW!

words cannot express my gratitude, nor can it express how impressed I am :)

Learned something new today! thank you!!!
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top