Noxqss38242
Board Regular
- Joined
- Sep 15, 2017
- Messages
- 225
- Office Version
- 2016
Need to create 350 sheets based on data in column J
What kind of data do you have in column J?
Sub AddSheets()
Dim cl As Range
Dim Ky As Variant
Dim i As Long
With CreateObject("Scripting.dictionary")
For Each cl In Range("J2", Range("J" & Rows.Count).End(xlUp))
.Item(cl.Value) = .Item(cl.Value) + 1
Next cl
For Each Ky In .keys
If .Item(Ky) = 1 Then
Sheets.Add.name = Ky
Else
For i = 1 To .Item(Ky)
Sheets.Add.name = Ky & " (" & i & ")"
Next i
End If
Next Ky
End With
End Sub
Sub AddSheets()
Dim rng As Range, c As Range, LstRw As Long, sh As Worksheet
Dim worksh As Integer
Dim worksheetexists As Boolean
Set sh = Sheets("Sheet1")
With sh
LstRw = .Cells(.Rows.Count, "J").End(xlUp).Row
Set rng = .Range("J2:J" & LstRw)
End With
Application.ScreenUpdating = False
For Each c In rng.Cells
worksh = Application.Sheets.Count
worksheetexists = False
For x = 1 To worksh
If Worksheets(x).Name = c Then
worksheetexists = True
Sheets(c.Value).Copy After:=Worksheets(Sheets.Count)
'MsgBox c & ", already Exists"
Exit For
End If
Next x
If worksheetexists = False Then
'MsgBox "Nope"
Sheets.Add After:=Worksheets(Sheets.Count)
ActiveSheet.Name = c
End If
Next c
sh.Select
End Sub
Sub DeleteShts()
Dim sh As Worksheet
Application.DisplayAlerts = False
For Each sh In Sheets
If sh.Name <> "Sheet1" Then sh.Delete
Next sh
End Sub