|
Sub test()
Dim wb As Workbook
Dim ws As Worksheet
Dim rng As Range
With Sheets("sheet2")
r = .Cells(.Rows.Count, 3).End(3).Row
Set rng = .Range("a3:i" & r)
End With
Set wb = Workbooks.Add
Set ws = wb.Sheets(2)
With wb.Sheets(1)
rng.Copy .Range("A2")
.Rows("1:2").Copy ws.Range("A1")
r = .Cells(.Rows.Count, 3).End(3).Row
last = r
xh = 1
Do While last > 3
For i = 3 To last
If .Cells(i, 1).MergeArea.Cells(1, 1).Address = .Cells(i, 1).Address Then
k = .Cells(i, 1)
If k = xh Then
If .Cells(i, 1).MergeCells = True Then
hs = .Cells(i, 1).MergeArea.Count
.Range("A" & i & ":I" & i + hs - 1).Cut Destination:=ws.Range("A" & ws.Cells(ws.Rows.Count, 3).End(3).Row + 1)
Else
.Range("A" & i & ":I" & i).Cut Destination:=ws.Range("A" & ws.Cells(ws.Rows.Count, 3).End(3).Row + 1)
End If
With ws
End With
End If
End If
Next
xh = xh + 1
r = .Cells(.Rows.Count, 3).End(3).Row
last = r
Loop
.Rows("1:2").Copy ws.Range("A1")
End With
End Sub |
评分
-
1
查看全部评分
-
|