Advertisement
lilysecret

Add New Named Worksheets

Sep 19th, 2018
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub QuickAddTabs()
  2.  
  3. ''make new worksheets with names stored in the first column of a worksheet
  4.  
  5. Dim cM As Range
  6. Dim lastRow As Long
  7.  
  8. On Error GoTo errmsg ''go to error handling if an error occurs
  9.  
  10. lastRow = Cells(Rows.Count, 1).End(xlUp).Row
  11.  
  12. For Each cM In ActiveSheet.Range("A1:A" & lastRow)
  13.     Sheets.Add after:=Sheets(Sheets.Count)
  14.     Sheets(ActiveSheet.Name).Name = cM.Value
  15. Next cM
  16.  
  17. Done:
  18.     Exit Sub
  19.    
  20. errmsg:
  21.     MsgBox "The Following Error Occurred: " & Err.Description
  22. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement