|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
难道是我传错文件了?
- Sub test2()
- Set d = CreateObject("scripting.dictionary")
- ar = Sheets("New").UsedRange
- br = Sheets("Data").UsedRange
- mc = 0
- ReDim cr(1 To UBound(ar) + UBound(br), 1 To UBound(ar, 2) + UBound(br, 2))
- For i = 1 To UBound(br)
- s = br(i, 1)
- If Not d.exists(s) Then
- Set d(s) = CreateObject("scripting.dictionary")
- End If
- If Not d(s).exists(i) Then
- Set d(s)(i) = CreateObject("scripting.dictionary")
- End If
-
- For j = 2 To UBound(br, 2)
- If br(i, j) <> "" Then
- d(s)(i)(br(i, j)) = ""
- End If
- Next
- Next
- lr = UBound(br)
- For i = 1 To UBound(ar)
- s = ar(i, 1)
- If d.exists(s) Then
- For Each k In d(s).keys
- For j = 2 To UBound(ar, 2)
- If ar(i, j) <> "" Then
- d(s)(k)(ar(i, j)) = ""
- End If
- Next
- Next
- Else
- lr = lr + 1
- Set d(s) = CreateObject("scripting.dictionary")
- Set d(s)(lr) = CreateObject("scripting.dictionary")
- For j = 2 To UBound(ar, 2)
- If ar(i, j) <> "" Then
- d(s)(lr)(ar(i, j)) = ""
- End If
- Next
- End If
- Next
-
- For Each k In d.keys
- For Each kk In d(k).keys
- cr(kk, 1) = k
- j = 1
- For Each kkk In d(k)(kk).keys
- j = j + 1
- cr(kk, j) = kkk
- Next
- If j > mc Then mc = j
- Next
- Next
-
- With Sheets("Update")
- .UsedRange.Offset(, 6).Clear
- .Range("g1").Resize(lr, mc) = cr
- .Range("g1").Resize(lr, mc).HorizontalAlignment = xlCenter
- .Cells(UBound(br), "g").Resize(1, mc).Borders(xlEdgeBottom).LineStyle = xlDouble
- End With
- Set d = Nothing
- End Sub
复制代码 |
|