|
- Sub test1()
- Dim ar, dict As Object, titleRow As Long, splitCol As Long
- Dim strPath As String, strKey As String, colSize As Long, i As Long
- Application.ScreenUpdating = False
- titleRow = 1
- ' splitCol = 5
- strPath = ThisWorkbook.Path & "\分簿\"
- If Dir(strPath, vbDirectory) = "" Then MkDir strPath
- Set dict = CreateObject("Scripting.Dictionary")
- With Worksheets("出库单明细导入")
- ar = .Range("A1").CurrentRegion
- colSize = UBound(ar, 2)
- For i = titleRow + 1 To UBound(ar)
- strKey = Trim(ar(i, 4)) & "-" & Trim(ar(i, 5)) & "-" & Trim(ar(i, 6))
- If Len(strKey) Then
- If Not dict.Exists(strKey) Then Set dict(strKey) = .Range("A1").Resize(titleRow, colSize)
- Set dict(strKey) = Union(dict(strKey), .Cells(i, 1).Resize(, colSize))
- End If
- Next
- End With
- Application.DisplayAlerts = False
- For i = 0 To dict.Count - 1
- With Workbooks.Add
- With .Worksheets(1)
- .Name = dict.Keys()(i)
- dict.Items()(i).Copy .Range("A1")
- .DrawingObjects.Delete
- .Columns.AutoFit
- End With
- .SaveAs strPath & dict.Keys()(i), 51
- .Close
- End With
- Next
- Set dict = Nothing
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- Beep
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|