I've got
everything working to create a job shop worksheet for each part on a
master material list. I click a button after getting the list right,
and it creates a sheet for each part, and at the end brings the
master sheet back active. I've got a few problems. One is how can I,
at the end of the script, have it sort the sheets in alphabetic
order. I have another script that will do it, but I have to run it
separate. Second, I'd like it to only create sheets with new part
numbers, rather than replacing all sheets if I run it more than
once. I'll paste the code if that helps.
Sub PagesByDescription()
Dim rRange As Range, rCell As Range
Dim wSheet As Worksheet
Dim wSheetStart As Worksheet
Dim strText As String
Set wSheetStart = ActiveSheet
wSheetStart.AutoFilterMode = False
'Set a range variable to the correct item column
Set rRange = Range("a4:o4", Range("a1000:n1000").End(xlUp))
'Delete any sheet called "UniqueList"
'Turn off run time errors & delete alert
On Error Resume Next
Application.DisplayAlerts = False
Worksheets("4 UniqueList").Delete
'Add a sheet called "4 UniqueList"
Worksheets.Add().Name = "4 UniqueList"
'Filter the Set range so only a unique list is created
With Worksheets("4 UniqueList")
rRange.AdvancedFilter xlFilterCopy, , _
Worksheets("4 UniqueList").Range("a1"), True
'Set a range variable to the unique list, less the
heading.
Set rRange = .Range("a2", .Range("a65000").End
(xlUp))
End With
On Error Resume Next
With wSheetStart
For Each rCell In rRange
strText = rCell
.Range("a2").AutoFilter 1, strText
Worksheets(strText).Delete
'Add a sheet named as content of rCell
Sheets.Add(Type:="worksheet").Name = strText
Range("C2").Formula = strText
Next rCell
End With
With wSheetStart
.AutoFilterMode = False
.Activate
End With
On Error GoTo 0
Application.DisplayAlerts = True
End Sub