|
发表于 2013-2-22 10:12
|
显示全部楼层
本楼为最佳答案
- Sub 合并数据()
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Sheets("原数据").Columns("A:I").Copy
- With Sheets("结果")
- .Cells.Clear
- Sheets("原数据").Columns("A:I").Copy
- .Columns("A:A").Insert Shift:=xlToRight
- Application.CutCopyMode = False
- For I = 1 To .Range("I65536").End(xlUp).Row
- Select Case .Range("I" & I)
- Case "标题"
- .Range(.Cells(I, 1), .Cells(I, 7)).Merge
- .Range(.Cells(I, 1), .Cells(I, 7)).HorizontalAlignment = xlCenter
- Case 2
- .Range(.Cells(I, 1), .Cells(I, 7)).Merge
- .Range(.Cells(I, 1), .Cells(I, 7)).HorizontalAlignment = xlLeft
- Case 1
- .Range(.Cells(I, 1), .Cells(I, 2)).Merge
- .Range(.Cells(I, 1), .Cells(I, 2)).HorizontalAlignment = xlLeft
- .Range(.Cells(I, 3), .Cells(I, 4)).Merge
- .Range(.Cells(I, 3), .Cells(I, 4)).HorizontalAlignment = xlLeft
- .Range(.Cells(I, 5), .Cells(I, 7)).Merge
- .Range(.Cells(I, 5), .Cells(I, 7)).HorizontalAlignment = xlLeft
- End Select
- Next I
- .Columns("H:I").Clear
- .Rows("1:1").Delete
- Sheets("样表").Columns("A:G").Copy
- .Columns("A:G").PasteSpecial Paste:=xlPasteColumnWidths
- Application.CutCopyMode = False
- .Rows("1:" & .Range("A65536").End(xlUp).Row).RowHeight = 18
- End With
- Application.ScreenUpdating = True
- Application.DisplayAlerts = True
- End Sub
复制代码 |
|