|
发表于 2013-1-27 21:33
|
显示全部楼层
本楼为最佳答案
- Sub 合并()
- Dim wb As Workbook
- Dim i&, addr$, j&, LastRow&, FirstRow&
- Application.ScreenUpdating = False
- With ThisWorkbook
- For i = 1 To .Worksheets.Count
- Debug.Print .Worksheets(i).Name,
- If .Worksheets(i).Name Like "*.*.*" Then
- .Worksheets(i).UsedRange.Copy
- Exit For
- End If
- Next
- Set wb = Workbooks.Add
- Cells(Rows.Count, 2).End(xlUp).PasteSpecial
- LastRow = Cells(Rows.Count, 2).End(xlUp).Row
- Range("a5:a" & LastRow) = .Worksheets(i).Name
- For j = i + 1 To .Worksheets.Count
- If .Worksheets(j).Name Like "*.*.*" Then
- FirstRow = Cells(Rows.Count, 2).End(xlUp).Row + 1
- addr = Replace(.Worksheets(j).UsedRange.Address, "$A$1", "$A$5")
- .Worksheets(j).Range(addr).Copy
- Cells(FirstRow, 2).PasteSpecial
- LastRow = Cells(Rows.Count, 2).End(xlUp).Row
- Range("a" & FirstRow & ":a" & LastRow) = .Worksheets(j).Name
- End If
- Next
- End With
- Application.ScreenUpdating = True
- MsgBox "工作表已经合并到" & wb.Name & ",请保存"
- End Sub
复制代码 |
评分
-
查看全部评分
|