|
Sub qs()
Dim wb As Workbook, xb As Workbook, dic As Object, sht As Worksheet, rng As Range
Set wb = ThisWorkbook: Set dic = CreateObject("scripting.dictionary")
Set sht = wb.Sheets("电子送货单")
ph = ThisWorkbook.Path & "\"
arr = Sheet1.Range("q2:q" & Sheet1.Cells(Rows.Count, "q").End(3).Row)
For i = 1 To UBound(arr)
If Not dic.exists(arr(i, 1)) Then
If arr(i, 1) <> Empty Then
dic(arr(i, 1)) = ""
End If
End If
Next
yyy = dic.keys
Application.ScreenUpdating = False: Application.DisplayAlerts = False
For Each k In dic.keys
sht.Copy
Set xb = ActiveWorkbook
rw = xb.Sheets(1).Cells(Rows.Count, "q").End(3).Row
' xb.Sheets(1).Range("A" & 10).Resize(1, 17).Select
For i = rw To 2 Step -1
If xb.Sheets(1).Range("q" & i).Value <> k Then
xb.Sheets(1).Range("A" & i).Resize(1, 17).Delete Shift:=xlUp
Else
xb.Sheets(1).Range("q" & i).Value = ""
End If
Next
xb.SaveAs ph & k & ".xlsx"
xb.Close
Next
Application.ScreenUpdating = True: Application.DisplayAlerts = True
Set dic = Nothing: Set wb = Nothing: Set xb = Nothing
MsgBox "完成!"
End Sub
|
|