|
Sub TEST()
Dim arr, i&, dic As Object, vKey, wks As Worksheet
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
arr = [B1].CurrentRegion
For i = 2 To UBound(arr)
vKey = Mid(arr(i, 1), 1, 1)
If Not dic.exists(vKey) Then
Set dic(vKey) = CreateObject("Scripting.Dictionary")
End If
dic(vKey)(arr(i, 1)) = ""
Next i
For Each vKey In dic.keys
If bIsWorksheetExist(CStr(vKey)) Then
With Worksheets(vKey)
.[A1].CurrentRegion.Cells.Clear
.[A1] = "号码"
.[A2].Resize(dic(vKey).Count) = Application.Transpose(dic(vKey).keys)
End With
End If
Next
Set dic = Nothing
Application.ScreenUpdating = True
Beep
End Sub
Public Function bIsWorksheetExist(wksName As String) As Boolean
On Error Resume Next
bIsWorksheetExist = Sheets(wksName).Name = wksName
End Function |
|