|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
写了半天,一看有点问题,就是以为你表中的数据是填好的呢
Sub tees()
Dim Mypath$, Myname$
Dim wb As Workbook
Dim ws As Worksheet
Dim sht As Worksheet
Set sht = ThisWorkbook.Sheets("Sheet1")
Set d = CreateObject("scripting.dictionary")
Mypath = ThisWorkbook.Path & "\本月实际销售\"
Myname = Dir(Mypath & "*.xls*")
Do While Myname <> ""
Set wb = GetObject(Mypath & Myname)
With wb.Sheets(1)
arr = .Range("A1").CurrentRegion
For j = 1 To UBound(arr, 2)
Select Case arr(1, j)
Case Is = "销售人"
xsr = j
Case Is = "客户名称"
khmc = j
Case Is = "流向数量", "数量"
lx = j
Case Is = "规格"
gg = j
End Select
Next
For i = 2 To UBound(arr)
If InStr(arr(i, gg), "毫克") Then
arr(i, gg) = Replace(arr(i, gg), "毫克", "mg")
End If
If InStr(arr(i, gg), "s") Then
arr(i, gg) = Replace(arr(i, gg), "s", "片")
End If
If Not d.exists(arr(i, xsr)) Then
Set d(arr(i, xsr)) = CreateObject("scripting.dictionary")
End If
If Not d(arr(i, xsr)).exists(arr(i, khmc)) Then
Set d(arr(i, xsr))(arr(i, khmc)) = CreateObject("scripting.dictionary")
End If
d(arr(i, xsr))(arr(i, khmc))(arr(i, gg)) = d(arr(i, xsr))(arr(i, khmc))(arr(i, gg)) + arr(i, lx)
Next
For Each aa In d.keys
With sht
For i = 5 To 13
If .Cells(i, 2) = aa Then
For Each bb In d(aa).keys
If bb = .Cells(i, 3) Then
For Each cc In d(aa)(bb).keys
For k = 4 To 19
If .Cells(3, k).MergeArea.Cells(1, 1).Address = .Cells(3, k).Address Then
If InStr(.Cells(3, k).Value, cc) Then
.Cells(i, k + 2) = d(aa)(bb)(cc)
End If
End If
Next
Next
End If
Next
End If
Next
End With
Next
d.RemoveAll
wb.Close False
End With
Myname = Dir
Loop
End Sub |
|