|
楼主 |
发表于 2018-8-19 16:41
|
显示全部楼层
Sub 工作簿拆分()
Dim arr, d As New Dictionary, i%
arr = Sheet1.UsedRange
Application.ScreenUpdating = False
For i = 2 To UBound(arr)
d(arr(i, 2)) = ""
Next i
Dim wb As Workbook, brr(1 To 20, 1 To 7), j%, k%, fileName$
For j = 0 To d.Count - 1
Erase brr()
brr(1, 1) = "日期": brr(1, 2) = "入库数量": brr(1, 3) = "出库数量": brr(1, 4) = "单价": brr(1, 5) = "入库金额": brr(1, 6) = "出库金额": brr(1, 7) = "备注"
k = 1
For i = 2 To UBound(arr)
If arr(i, 2) = d.Keys()(j) Then
k = k + 1
brr(k, 1) = arr(i, 1)
brr(k, 2) = arr(i, 2)
brr(k, 3) = arr(i, 3)
brr(k, 4) = arr(i, 4)
brr(k, 5) = arr(i, 5)
brr(k, 6) = arr(i, 6)
brr(k, 7) = arr(i, 7)
End If
Next i
fileName = ThisWorkbook.Path & "\" & d.Keys()(j) & ".xlsx"
If FileExists(fileName) Then Kill fileName
Set wb = Workbooks.Add
With wb
.Worksheets(1).Range("a1").Resize(k, 3) = brr
.Worksheets(1).Range("a:a").numberformatloca = "yyy/m/d"
.SaveAs fileName
.Close
End With
Next j
MsgBox "拆分完成!"
End Sub
Function FileExists(FullName As String) As Boolean
Dim strNname As String
strName = Dir(FullName)
If Len(strName) > 0 Then
FileExists = True
Else
FileExists = False
End If
End Function
请大神帮忙把这个对应的拆分代码诊断下,看到底问题出在哪里,谢谢!
|
|