巨复杂!求WPS VBA针对时间进行文件覆盖的操作指导?

大佬们觉得VBA能实现这么复杂的操作吗?已通过表格列出详情: 图一为问题简述;图二三为表格形成拆解
广东省
浏览 937
收藏
2
分享
2 +1
5
+1
全部评论 5
 
郑亿Oscar
郑亿Oscar

创作者俱乐部成员

评论区的字数限制 你从下往上复制用这个代码试试
· 浙江省
回复
 
郑亿Oscar
郑亿Oscar

创作者俱乐部成员

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
· 浙江省
回复
 
郑亿Oscar
郑亿Oscar

创作者俱乐部成员

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
· 浙江省
回复
 
郑亿Oscar
郑亿Oscar

创作者俱乐部成员

' 设置源工作表和目标工作表 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
· 浙江省
回复
 
郑亿Oscar
郑亿Oscar

创作者俱乐部成员

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
· 浙江省
回复