|
楼主 |
发表于 2023-2-2 20:31
|
显示全部楼层
老师,因后面这段代码看不懂,感觉好象有点多余,我把你的代码做了如下修正:
Sub 多表合并() '//2023.2.2
Dim arr, brr, d
Set d = CreateObject("Scripting.Dictionary")
Set sht = Sheets("合并")
Dim tm: tm = Timer
Application.ScreenUpdating = False
With sht
r = .Cells(.Rows.Count, "a").End(xlUp).Row
' .Range("a6:h" & r).Clear '
.Range("a6:F" & r).Clear '楼改
End With
m = 0: N = 0: y = 0
For Each sh In Sheets
If sh.Name <> sht.Name Then
N = N + 1
With sh
For x = 1 To 4
y = y + 1
l = (x - 1) * 7
s = .Cells(2, 2 + l)
d(s) = .Cells(2, 5 + l)
r1 = .Cells(.Rows.Count, 2 + l).End(xlUp).Row
r = IIf(y = 1, 6, sht.Cells(sht.Rows.Count, "a").End(xlUp).Row + 1)
If r1 > 3 Then .Range(.Cells(4, 1 + l), .Cells(r1, 7 + l)).Copy sht.Cells(r, 1)
Next
End With
End If
Next
' With sht '楼:上面已复制成功,只不过A列顺序不对,故只要解决A列排序即可。
' arr = .[i3:t4]
' For j = 1 To UBound(arr, 2)
' s = arr(1, j)
' arr(2, j) = d(s)
' Next
' .[i3:t4] = arr
' r = .Cells(.Rows.Count, "a").End(xlUp).Row
' .[b2] = y & "个群成员": .[e2] = r - 5: .[u4] = r - 5
' For j = 6 To r
' m = m + 1
' .Cells(j, 1) = m '//序列号
' Next j
' .Range("a6:h" & r).Borders.LineStyle = 1
' End With
' Range("A6").Select
' Range(Selection, Selection.End(xlDown)).Select
Set sht = Sheets("合并") '楼:上面不要,改成下面简单的A列赋序号。
With sht
r = .Cells(.Rows.Count, "a").End(xlUp).Row
End With
For j = 6 To r
m = m + 1
Cells(j, 1) = m '//序列号
Next j '楼:改成此。
Application.ScreenUpdating = True
MsgBox "合并完毕,共用时: " & Format(Timer - tm, "0.000秒"), , "提示"
End Sub
若有改错,敬请理解。 |
|