• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

creating new sheets based on dynamic list

ysherriff

Member
to al,

how are you? I have a macro that creates and renames sheets based on dynamic list. the list range changes based on offset function.

The issue is the macro wants to keep creating blank sheets and rename it. I get an error message because when they create the new sheet, there is not a name associated with it. How can I effectively tell this macro to stop creating new sheets once it reach the end of the list. the text highlighted in red is where the error lies.

Code:
 For i = 1 To filecount
 
  Range("PTL_NAME_RNG").Select
  Selection.ClearContents
 
  Set MyRange = Sheets("Control").Range("PTL_NAME_START").Offset(i, 0)
  Set MyRange = Range(MyRange, MyRange.End(xlDown))
 


For Each MyCell In MyRange
  Sheets("Template").Copy After:=Sheets(Sheets.Count) 'creates a new worksheet
  Sheets(Sheets.Count).Name = MyCell.Value ' renames the new worksheet
  Range("PTL_NAME") = MyCell.Value
  ActiveSheet.Protect Password:="ops", DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFiltering:=True
  Next MyCell]


I have uploaded the template file and the generator file.

Thanks for your help.
 

Attachments

  • Performance Notes and Comments Generator v.01.xlsm
    55.5 KB · Views: 2
  • DSM - Performance Notes and Comments Template.xls
    56.5 KB · Views: 1
Back
Top