约定的童话 发表于 2019-6-15 08:15
Sub 合并()
Dim i, n, m1, k, k1, m2, arr1, arr2, arr3(1 To 100, 1 To 1), brr(1 To 100, 1 To 1) ...
感谢,只是表中不只是固定的十几行数据,我尝试改下以适应多个数据时,结果中间出现了空行……请大神帮修正下
Sub 合并()
Dim i, n, m1, k, k1, m2, arr1, arr2, arr3(1 To 400, 1 To 1), brr(1 To 400, 1 To 1), d As Object
Set d = CreateObject("scripting.dictionary")
arr1 = Sheets("上公示").[B1:B200]: arr2 = Sheets("下公示").[B2:B200]
'以下是数组合并部分
For m1 = LBound(arr1) To UBound(arr1)
k = k + 1: arr3(k, 1) = arr1(m1, 1)
Next
For m2 = LBound(arr2) To UBound(arr2)
k1 = k1 + 1: arr3(k + k1, 1) = arr2(m2, 1)
Next
'******************
For i = 2 To UBound(arr3)
t = arr3(i, 1)
If Not d.exists(t) Then
n = n + 1
d(t) = n
If n <> i Then
brr(n, 1) = arr3(i, 1)
End If
End If
Next
[b2].Resize(UBound(brr), 1) = brr
End Sub
结果:
|