Try this and let me know
- place code below in the SHEET module
(right click on sheet tab \ view code \ paste in window on right)
- and then run CreateSheets
Place at the top -before all other procedures (makes variables available to all procedures in same module)
Code:
Option Explicit
Private Ops As Collection, Op As Variant
Private DataRange As Range, OpsRange As Range, Cel As Range, MatchRange As Range
Private LastRow As Long, r As Long
Private SheetName As String
Private ws As Worksheet
Main procedure calls other subs
Code:
Sub CreateSheets()
Optimise True
SetRanges
CreateUniqueList
AddSheets
CopyRows
Optimise False
End Sub
Other subs
Code:
Private Sub Optimise(OnOff As Boolean)
With Application
Select Case OnOff
Case True: .ScreenUpdating = False: .Calculation = xlCalculationManual
Case False: .ScreenUpdating = True: .Calculation = xlCalculationAutomatic
End Select
End With
End Sub
Private Sub SetRanges()
Set DataRange = Me.Cells(1).CurrentRegion
With DataRange
Set OpsRange = .Offset(1, 6).Resize(.Rows.Count - 1, .Columns.Count - 6)
LastRow = .Rows.Count
End With
End Sub
Private Sub CreateUniqueList()
Set Ops = New Collection
On Error Resume Next 'required to get unique list this way
For Each Cel In OpsRange
If Cel <> vbNullString Then Ops.Add Cel, Cel
Next Cel
End Sub
Private Sub AddSheets() 'deletes old one first if it exists with same name
Application.DisplayAlerts = False
On Error Resume Next 'sheet name may be invalid or sheet may not exist
For Each Op In Ops
SheetName = Op
Sheets(SheetName).Delete
Set ws = Sheets.Add(After:=Sheets(Sheets.Count))
ws.Name = SheetName
Me.Rows(1).Copy ws.Cells(1)
Next
Application.DisplayAlerts = True
End Sub
Private Sub CopyRows()
On Error Resume Next
For Each Op In Ops
SheetName = Op
Set ws = Sheets(SheetName)
For r = 2 To LastRow
Set MatchRange = OpsRange.Resize(1).Offset(r - 2)
If WorksheetFunction.CountIf(MatchRange, SheetName) > 0 Then
Me.Rows(r).Copy ws.Cells(Rows.Count, 1).End(xlUp).Offset(1)
End If
Next r
Next Op
End Sub
I avoided filtering - with only 250 rows copying one row at a time should be very quick