我有一个包含 116 张工作表的 excel 文件,我想将其附加到一张工作表中(“Tab_Appended”)。我尝试了以下代码并且它有效。但是,工作表中的 A 列未粘贴到 Tab_Appended - 我必须在哪里更改代码才能实现除标题行之外的所有数据都复制到 Tab_Appended?
顺便说一句,我排除了几张带有“case”的表格是否有更优雅的方法来排除包含字符串“legend”的所有表格,而不是我列出所有表格?
Sub SummurizeSheets()
Dim ws As Worksheet
Dim lastRng As Range
Dim lastCll As Range
Application.ScreenUpdating = False
Sheets("Tab_Appended").Activate
For Each ws In Worksheets
Set lastRng = Range("A65536").End(xlUp).Offset(1, 0)
Select Case ws.Name
Case "Tab_Appended", "Legende 1", "Legende 2", "Legende 3", "Legende 4", "Legende 5", "Legende 6", "Legende 7", "Legende 8", "Legende 9", "Legende 10", "Legende 11", "Legende 12", "Legende 13"
'do nothing
Case Else
Set lastCll = ws.Columns(1).Find(What:="*", After:=ws.Range("A1"), SearchDirection:=xlPrevious)
ws.Range("A2:" & lastCll.Address).Copy
Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)
'add sheet name before data
lastRng.Resize(lastCll.Row - 1) = ws.Name
End Select
Next ws
Columns("A").SpecialCells(xlBlanks).EntireRow.Delete (xlUp)
Application.ScreenUpdating = True
End Sub