modified test-macro
Sub test()
Dim rng As Range, a, i As Long, temp As String
Application.ScreenUpdating = False
Set rng = Sheets("names").Range("b2").CurrentRegion
With rng
a = .Offset(2 - .Row, 2 - .Column).Resize(, 1).Value 'Always start with B2
End With
With CreateObject("System.Collections.SortedList")
For i = 1 To UBound(a, 1)
temp = UCase$(Left$(a(i, 1), 1))
If temp <> "" Then
If Not .Contains(temp) Then
Set .Item(temp) = rng.Rows(i)
Else
Set .Item(temp) = Union(.Item(temp), rng.Rows(i))
End If
End If
Next
For i = .Count - 1 To 0 Step -1
If Not IsSheetExists(.GetKey(i)) Then
Sheets.Add().Name = .GetKey(i)
End If
Sheets(.GetKey(i)).Move after:=rng.Parent
.GetByIndex(i).Copy Sheets(.GetKey(i)).Cells(2, 2)
With Sheets(.GetKey(i)).UsedRange
With .Offset(, 1 - .Column).Resize(, 1)
.FormulaR1C1 = "=row()-1"
.Value = .Value
End With
.Parent.Rows(1).EntireColumn.AutoFit
End With
Next
End With
Application.ScreenUpdating = True
End Sub
Bookmarks