|
楼主 |
发表于 2018-10-15 15:22
|
显示全部楼层
- Sub 汇总()
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- Set d2 = CreateObject("scripting.dictionary")
- Dim str As String
- Dim temp As String
- arr = Sheets("采购订单").[a1].CurrentRegion.Offset(1)
- brr = Sheets("采购入库").[a1].CurrentRegion.Offset(1)
- crr = Sheets("销售出库").[a1].CurrentRegion.Offset(1)
- For i = 1 To UBound(arr)
- If arr(i, 4) <> "" Then
- If arr(i, 5) <> "" Then
- str = arr(i, 5) & "@" & arr(i, 6)
- If Not d.exists(arr(i, 4)) Then
- Set d(arr(i, 4)) = CreateObject("scripting.dictionary")
- End If
- d(arr(i, 4))(str) = ""
- End If
- End If
- Next
- For j = 1 To UBound(brr)
- If brr(j, 12) <> "" Then
- If Not d1.exists(brr(j, 12)) Then
- If brr(j, 5) <> "" Then
- 'd1(brr(j, 7)) = d1(brr(j, 7)) + brr(j, 5)
- temp = brr(j, 5)
- Else
- d1(brr(j, 12)) = d1(brr(j, 12)) + temp
- End If
- End If
- If brr(j, 5) <> "" Then
- d1(brr(j, 12)) = d1(brr(j, 12)) + brr(j, 5)
- End If
- End If
-
- Next
- For m = 1 To UBound(crr)
- If crr(m, 14) <> "" Then
- If Not d2.exists(crr(m, 14)) Then
- If crr(m, 4) <> "" Then
- temp = crr(m, 4)
- Else
- d2(crr(m, 14)) = d2(crr(m, 14)) + temp
- End If
- End If
- If crr(m, 4) <> "" Then
- d2(crr(m, 14)) = d2(crr(m, 14)) + crr(m, 4)
- End If
- End If
- Next
- kr1 = d2.keys
- cr1 = d2.items
- 'kr = d.keys
- 'cr = d.items
- ReDim myarr(1 To 1000, 1 To 5)
- For Each dd In d.keys
- For Each ddd In d(dd).keys
- k = k + 1
- myarr(k, 1) = dd
- myarr(k, 2) = Split(ddd, "@")(0)
- myarr(k, 3) = Split(ddd, "@")(1)
-
- Next
- For Each dd1 In d1.keys
- If dd = dd1 Then
- myarr(k, 4) = d1(dd1)
- End If
- Next
-
- Next
- Sheets("汇总").[a2:e5200].ClearContents
- Sheets("汇总").[a2].Resize(k, 4) = myarr
- MySplit1
- n = Sheets("汇总").Range("d65536").End(3).Row
- For i = 2 To n
- For Each dd2 In d2.keys
- If dd2 = Sheets("汇总").Cells(i, 4) Then
- Sheets("汇总").Cells(i, 5) = d2(dd2)
- End If
- Next
- Next
- 'MySplit2
- 'MsgBox "aa"
- End Sub
- Sub MySplit1()
- Dim str As String
- Application.ScreenUpdating = False
- With Sheets("汇总")
- i = .Range("a1048567").End(3).Row
- a:
- For j = 2 To i
- k = Len(Cells(j, 4)) / 9
- If k > 1 Then
- str = .Cells(j, 4)
- .Cells(j, 4) = Mid(str, 1, 9)
- For b = 1 To k - 1
- Rows(j + b).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
-
- .Cells(j + b, 4) = Mid(str, b * 9 + 1, 9)
- Next
- End If
- m = .Range("d1048567").End(3).Row
- If i < m Then
- i = m
- GoTo a
- End If
- Next
-
- End With
- Application.ScreenUpdating = True
- End Sub
- Sub MySplit2()
- Dim str As String
- Application.ScreenUpdating = False
- With Sheets("汇总")
- i = .Range("a1048567").End(3).Row
- b:
- For x = 2 To i
- k = Len(Cells(x, 5)) / 10
- If k > 1 Then
- str = .Cells(x, 5)
- .Cells(x, 5) = Mid(str, 1, 10)
- For b = 1 To k - 1
- Rows(x + b).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
-
- .Cells(x + b, 5) = Mid(str, b * 10 + 1, 10)
- .Cells(x + b, 4) = Cells(x + b - 1, 4)
- Next
- End If
- m = .Range("d1048567").End(3).Row
- If i < m Then
- i = m
- GoTo b
- End If
- Next
-
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码
自己研究了半边,搞了个代码,能达到效果了,有老师能帮我改进一下吗?谢谢! |
|