For Each wsNewTable In wbC.Sheets
If wsNewTable.Name <> "Sheet1" And wsNewTable.Name <> "Sheet2" Then
tableRowCount = wsNewTable.Cells(wsNewTable.Rows.Count, 1).End(xlUp).Row
Set rngSource = wsNewTable.Range("A1:Z" & tableRowCount)
lastRowC = wsC1.Cells(wsC1.Rows.Count, 1).End(xlUp).Row
Set rngDest = wsC1.Cells(lastRowC + 2, 1)
rngSource.Copy rngDest
End If
Next wsNewTable
End Sub
Set wbB = Workbooks.Open("路径\文件薄B.xlsx") ' 替换为实际的文件路径
Set wsB = wbB.Sheets("Sheet2") ' 替换为实际的工作表名称
lastRowB = wsB.Cells(wsB.Rows.Count, 1).End(xlUp).Row
Set rngSource = wsB.Range("A1:Z" & lastRowB)
Set rngDest = wsC1.Range("A1")
rngSource.Copy rngDest
' 关闭打开的工作簿
wbA.Close SaveChanges:=False
wbB.Close SaveChanges:=False
' 在汇总薄C的sheet1中复制各个新表格
Dim wsNewTable As Worksheet
Dim tableRowCount As Long
Dim lastRowC As Long
' 设置源工作表和目标工作表
Set wsA = wbA.Sheets("Sheet1") ' 替换为实际的工作表名称
Set wsC2 = wbC.Sheets("Sheet2") ' 替换为实际的工作表名称
Set wsC1 = wbC.Sheets("Sheet1") ' 替换为实际的工作表名称
' 复制文件薄A的sheet1到汇总薄C的sheet2
lastRowA = wsA.Cells(wsA.Rows.Count, 1).End(xlUp).Row
Set rngSource = wsA.Range("A1:Z" & lastRowA)
Set rngDest = wsC2.Range("A1")
rngSource.Copy rngDest
' 复制文件薄B的sheet2到汇总薄C的sheet3
Dim wbB As Workbook
Dim wsB As Worksheet
Dim lastRowB As Long
Sub CopyAndMergeData()
Dim wbA As Workbook
Dim wbC As Workbook
Dim wsA As Worksheet
Dim wsC2 As Worksheet
Dim wsC1 As Worksheet
Dim lastRowA As Long
Dim rngSource As Range
Dim rngDest As Range
' 打开文件薄A和汇总薄C
Set wbA = Workbooks.Open("路径\文件薄A.xlsx") ' 替换为实际的文件路径
Set wbC = ThisWorkbook ' 汇总薄C
创作者俱乐部成员
创作者俱乐部成员
创作者俱乐部成员
创作者俱乐部成员
创作者俱乐部成员