|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
套用的是“ykcbf1100”大神的代码,需汇总的数据是A站、B站、C站、D站,表格格式基本一样,就是列数有所增多,已按列数修改了代码,但还是不能使用,请求各位大神指点一下,教导一下类似的问题应如何修改代码,好学会后能自行修改了,谢谢!
Sub 合并工作表2() '//2024.1.21
Dim ss As Worksheet
Application.ScreenUpdating = False
Set Sh = Sheets("汇总")
Sh.UsedRange.Clear
For Each ss In Worksheets
If Val(ss.Name) Then
m = m + 1
With ss
If m = 1 Then
r1 = .Cells(Rows.Count, 1).End(3).Row
.Range("a1:ai" & r1).Copy Sh.Range("a1")
Else
r = Sh.Cells(Rows.Count, 1).End(3).Row
r1 = .Cells(Rows.Count, 1).End(3).Row
.Range("a3:ai" & r1).Copy Sh.Cells(r + 1, 1)
End If
End With
End If
Next
With Sh
r = .Cells(Rows.Count, 1).End(3).Row
For i = 3 To r
If .Cells(i, 1) = "" Then .Cells(i, 1) = 9999
Next
Set Rng = .Range("a3:ai" & r)
Rng.Sort .[a3], 1, , , , , , 1
r = .Columns(1).Find("9999").Row
.UsedRange.Offset(r - 1).Clear
End With
Application.ScreenUpdating = True
MsgBox "工作表合并完毕!"
End Sub
|
|