I know there are some threads with similar information. I have used some to come up with the following macro.
The macro is used to make a copy of a master sheet for every cell in Column A (after A2) that has data in it. It also names the sheet with the cell value and inserts the cell value in A2 on the new sheet.
The problem is that the macro is adding an extra sheet on the end (after all cells with values, it is adding one with the name:"Master (2)").
If anyone has any idea why this is the case, I would greatly appreciate an explanation.
(Sorry if my coding is atrocious, I am fairly new at VBA)
The macro is used to make a copy of a master sheet for every cell in Column A (after A2) that has data in it. It also names the sheet with the cell value and inserts the cell value in A2 on the new sheet.
The problem is that the macro is adding an extra sheet on the end (after all cells with values, it is adding one with the name:"Master (2)").
If anyone has any idea why this is the case, I would greatly appreciate an explanation.
(Sorry if my coding is atrocious, I am fairly new at VBA)
Code:
Sub CreateSheets()On Error GoTo Errorhandler
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim MyCell As Range, MyRange As Range
Set MyRange = Sheets("Sheet4").Range("A2")
Set MyRange = Range(MyRange, MyRange.End(xlDown))
For Each MyCell In MyRange
Sheets("Master").Copy after:=Sheets(Sheets.Count) 'COPY HIDDEN SHEET
Sheets(Sheets.Count).Visible = True 'MAKE NEW SHEET VISIBLE
Sheets(Sheets.Count).Name = MyCell.Value 'RENAME SHEET TO CELL VALUE
Sheets(Sheets.Count).Range("A2").Value = Sheets(Sheets.Count).Name
Next MyCell
Errorhandler:
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub