|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 一把小刀闯天下 于 2018-6-23 21:11 编辑
'自己测试一下,估计差不多
Option Explicit
Sub test()
Dim i, j, dic(3), sht, t, arr, n, cnt, key, s
For i = 0 To UBound(dic)
Set dic(i) = CreateObject("scripting.dictionary")
Next
n = 4
For Each sht In Sheets
With Sheets(sht.Name)
If InStr(sht.Name, "晶") Then
arr = .[a1].CurrentRegion
For i = 2 To UBound(arr, 1)
dic(2)(arr(i, 1)) = arr(i, 5) '物料代码->类型
If Not dic(3).exists(arr(i, 5)) Then
n = n + 1: dic(3)(arr(i, 5)) = n '类型种类
End If
Next
ElseIf sht.Name = "齐套明细" Then
arr = .[a1].CurrentRegion
For i = 2 To UBound(arr, 1)
dic(1)(arr(i, 1) & arr(i, 2)) = arr(i, 4) '指令、种类->已发数
If dic(0).exists(arr(i, 1)) Then '每个指令包含的物料代码
t = dic(0)(arr(i, 1)): ReDim Preserve t(UBound(t) + 1)
t(UBound(t)) = arr(i, 2): dic(0)(arr(i, 1)) = t
Else
dic(0)(arr(i, 1)) = Array(arr(i, 2))
End If
Next
End If
End With
Next
ReDim arr(1 To dic(0).Count, 1 To dic(3).Count + 4)
For Each key In dic(0).keys
ReDim n(1 To dic(3).Count + 4)
cnt = cnt + 1: arr(cnt, 1) = key: s = vbNullString
t = dic(0)(key) '单个指令中的物料代码
For i = 0 To UBound(t)
If dic(2).exists(t(i)) Then '按物料代码获取类型
If InStr(s, dic(2)(t(i))) = 0 Then s = s & dic(2)(t(i)) & "、"
n(dic(3)(dic(2)(t(i)))) = n(dic(3)(dic(2)(t(i)))) + dic(1)(key & t(i))
Else
s = s & "备件" & "、": n(4) = n(4) + dic(1)(key & t(i))
End If
Next
s = Left(s, Len(s) - 1): arr(cnt, 3) = s '类型
For i = 4 To UBound(arr, 2): arr(cnt, i) = n(i): Next '不同种类已发数汇总
Next
With Sheets("任务类型").[n1] '输出位置自己修改,作比较用
.Resize(Rows.Count, UBound(arr, 2)).ClearContents
.Offset(1).Resize(UBound(arr, 1), UBound(arr, 2)) = arr
.Offset(, 4).Resize(, dic(3).Count) = dic(3).keys
.Resize(, 4) = Split("指令号 类型 备件")
End With
End Sub
|
评分
-
1
查看全部评分
-
|