【发布时间】:2019-02-04 04:34:44
【问题描述】:
想法是将位于文件“文件路径”中的工作簿中的所有工作表1合并到工作簿,工作表“摘要” 所有文件都具有相同的标题,因此无需复制标题 例如:2个文件
这是我设法输入的代码:
Sub collate_data()
Dim folderpath As String
Dim filepath As String
Dim filename As String
Dim final As String
folderpath = ThisWorkbook.Sheets("input").Cells(1, 2).Text
filepath = folderpath & "*xlsx*"
filename = Dir(filepath)
smer = ThisWorkbook.Sheets("input").Cells(3, 2).Text
Dim lastrow As Long
Dim lastcolumn As Long
Do While filename <> ""
final = ThisWorkbook.Sheets("input").Cells(6, 2).Text
y = final & "Summary.xlsx"
Workbooks.Open (folderpath & filename)
lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlDown).Row
lastcolumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
Range(Cells(2, 1), Cells(lastrow, lastcolumn)).Select
Range(Cells(2, 1), Cells(lastrow, lastcolumn)).Copy
Application.DisplayAlerts = False
ActiveWorkbook.Close
Set x = Workbooks.Open(smer)
erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste = Worksheets("sheet1").Range(Cells(erow, 1), Cells(erow, 1))
filename = Dir
Loop
Application.DisplayAlerts = True
End Sub
【问题讨论】: