|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub test()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("基础数据")
r = .Cells(Rows.Count, 6).End(xlUp).Row '- 1
.Range("m3:p" & r) = Empty
ar = .Range("f1:p" & r)
For i = 3 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
d(Trim(ar(i, 1))) = i
End If
Next i
For j = 8 To UBound(ar, 2)
If Trim(ar(2, j)) <> "" Then
d(Trim(ar(2, j))) = j
End If
Next j
rs = .Cells(Rows.Count, 1).End(xlUp).Row
br = .Range("a1:d" & rs)
For i = 2 To UBound(br)
n = d(Trim(br(i, 3)))
m = d(Trim(br(i, 4)))
If n <> "" And m <> "" Then
If ar(n, m) = "" Then
ar(n, m) = br(i, 1)
Else
ar(n, m) = ar(n, m) & "、" & br(i, 1)
End If
End If
Next i
For i = 3 To UBound(ar)
For j = 8 To UBound(ar, 2)
.Cells(i, j + 5) = ar(i, j)
Next j
Next i
End With
MsgBox "ok!"
End Sub |
|