|
Option Explicit
Dim A, B(1 To 10 ^ 4, 1 To 5), s
'多个表
Sub test()
Dim i, x
Application.ScreenUpdating = False
Sheets(1).Select
A = ActiveSheet.UsedRange
s = 0
x = 3
For i = 3 To UBound(A)
If InStr(A(i, 1), "界址点坐标表") Then
Call test2(x, i - 2)
x = i + 2
End If
Next i
Call test2(x, i - 1)
Sheets(3).Select
Cells.Clear
[a1:d1].Value = Sheets(1).[a2:d2].Value
Range("a2").Resize(s, UBound(B, 2)) = B
Call test4
End Sub
'一个表
Sub test2(x, y)
' Debug.Print x, y
Dim i, j, p
For j = 1 To UBound(A, 2) Step 4
p = x
For i = x + 1 To y
If A(i, j) <> "" Then
Call test3(p, i - 1, j)
p = i
End If
Next i
Call test3(p, i - 1, j)
Next j
End Sub
'一个合并
Sub test3(p, q, c)
'Debug.Print p, q
Dim i
For i = p To q
s = s + 1
B(s, 1) = A(i, c)
B(s, 2) = A(i, c + 1)
B(s, 3) = A(i, c + 2)
B(s, 4) = A(i, c + 3)
Next i
End Sub
Sub test4()
Dim A, r, i, j
Application.DisplayAlerts = False
A = Range("a1").CurrentRegion
r = UBound(A)
For i = r To 2 Step -1
If r > i Then
If A(i, 1) <> "" Then
For j = 1 To 2
Range(Cells(i, j), Cells(r, j)).Merge
Next j
r = i - 1
End If
End If
Next
Range("a:d").EntireColumn.AutoFit
End Sub
3.rar
(43.12 KB, 下载次数: 2)
|
评分
-
查看全部评分
|