Sub sheets_from_col3()
Const cl& = 3
Const sh1 As String = "R1_1375_test"
Dim a As Variant, x As Worksheet, sh As Worksheet
Dim rws&, cls&, p&, i&, rr&, b As Boolean
Application.ScreenUpdating = False
Sheets(sh1).Activate
rws = Cells.Find("*", , , , xlByRows, xlPrevious).Row
cls = Cells.Find("*", , , , xlByColumns, xlPrevious).Column
Set x = Sheets.Add(After:=Sheets(sh1))
Sheets(sh1).Cells(1).Resize(rws, cls).Copy x.Cells(1)
Set a = x.Cells(1).Resize(rws, cls)
a.Sort a(1, cl), 2, Header:=xlYes
a = a.Resize(rws + 1)
p = 2
For i = p To rws + 1
If a(i, cl) <> a(p, cl) Then
b = False
For Each sh In Worksheets
If sh.Name = a(p, cl) Then b = True: Exit For
Next
If Not b Then
With Sheets.Add
.Name = a(p, cl)
x.Cells(1).Resize(, cls).Copy .Cells(1)
rr = .Cells.Find("*", , , , xlByRows, xlPrevious).Row + 1
x.Cells(p, 1).Resize(i - p, cls).Cut .Cells(rr, 1)
.Columns.AutoFit
End With
End If
p = i
End If
Next i
Application.DisplayAlerts = False
x.Delete
Application.DisplayAlerts = True
Sheets(sh1).Activate
Application.ScreenUpdating = True
End Sub
Bookmarks