|
本帖最后由 wxxydl 于 2017-12-16 14:20 编辑
这种方式汇总 见附件
Sub huiz()
Dim d As Object, dian_name As String, wb As Workbook
Dim f, arr, brr, ws As Worksheet
Dim fd As FileDialog
Dim crr(1 To 100, 1 To 11)
On Error Resume Next
Set d = CreateObject("scripting.dictionary")
Set fd = Application.FileDialog(msoFileDialogFilePicker)
dd = Array("序号", "订货日期", "门店名称", "公司", "水龙头", "M5水管", "X8锁", "总额", "收件地址", "发票号码", "备注")
For i = 1 To UBound(crr, 2)
crr(1, i) = dd(i - 1)
Next
k = 2
With fd
.AllowMultiSelect = True
.Filters.Add "excel文件", "*.xls*"
.Title = "请选择要汇总的文件"
If .Show = -1 Then
For Each f In .SelectedItems
crr(k, 1) = k - 1
Set wb = Application.Workbooks(Mid(f, InStrRev(f, "\") + 1, 255))
If Err.Number > 0 Then
Err.Clear
Set wb = Application.Workbooks.Open(f)
End If
Set ws = wb.Worksheets("sheet1")
With ws
arr = .[a1].CurrentRegion
dian_name = .Cells(UBound(arr) + 4, 2)
sj = .Cells(UBound(arr) + 5, 2)
gs = .Cells(UBound(arr) + 4, 5)
dz = .Cells(UBound(arr) + 2, 2)
End With
wb.Close
For i = 3 To UBound(arr)
If arr(i, 2) <> "" Then
d((dian_name) & (arr(i, 2))) = arr(i, 4)
crr(k, i + 2) = d((dian_name) & (crr(1, i + 2)))
crr(k, 8) = crr(k, 8) + arr(i, 5)
End If
Next
crr(k, 2) = sj
crr(k, 3) = dian_name
crr(k, 4) = gs
crr(k, 9) = dz
k = k + 1
Next
End If
End With
ActiveWorkbook.Worksheets("sheet1").[a2].Resize(100, 11) = crr
End Sub
|
|