|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 合并()
Dim d As Object
Dim ar As Variant
Dim br()
Set d = CreateObject("scripting.dictionary")
ReDim br(1 To 10000, 1 To 500)
n = 1: m = 1
For Each sh In Sheets
If sh.Name <> "合并" Then
ar = sh.[a1].CurrentRegion
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
If Not d.exists(ar(i, 1)) Then
n = n + 1
br(n, 1) = ar(i, 1)
d(br(n, 1)) = n
End If
For j = 2 To UBound(ar, 2)
If Not d.exists(Trim(ar(1, j))) Then
m = m + 1
br(1, m) = ar(1, j)
d(br(1, m)) = m
x = d(Trim(ar(i, 1)))
End If
y = d(Trim(ar(1, j)))
x = d(ar(i, 1))
If x <> "" And y <> "" Then
br(x, y) = ar(i, j)
End If
Next j
End If
Next i
End If
Next sh
With Sheets("合并")
.[a1].CurrentRegion = Empty
.[a1].Resize(n, m) = br
End With
MsgBox "完毕!", 64, "3190496160 提醒"
End Sub
|
|