|
自己先在同目录下建立“发货明细”文件夹:
Sub lsc()
Set rng = Range("A1:J1")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
arr = [A1].CurrentRegion
Set d = CreateObject("scripting.dictionary")
For i = 2 To UBound(arr)
s = Left(arr(i, 1), 1)
If Not d.exists(s) Then
Set d(s) = Cells(i, 1).Resize(1, 10)
Else
Set d(s) = Union(d(s), Cells(i, 1).Resize(1, 10))
End If
Next
k = d.keys
t = d.items
For i = 0 To d.Count - 1
Set wb = Workbooks.Add(xlWBATWorksheet)
With wb.Sheets(1)
rng.Copy .[A1]: t(i).Copy .[A2]
For j = 1 To UBound(arr, 2)
.Columns(j).ColumnWidth = ThisWorkbook.ActiveSheet.Columns(j).ColumnWidth
Next
End With
wb.SaveAs Filename:=ThisWorkbook.Path & "\发货明细\" & k(i), FileFormat:=xlExcel12
wb.Close
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "完毕"
End Sub |
|