excel图表怎么合并多个工作簿中的数据( 二 )


ByVal xlsCommonSheet AsString, ByVal startRowCopy As Long)
‘ 打开的工作簿对象
Dim openWb As Workbook
‘ 工作表中最后一个数据单元格所在的行
Dim lastRowx As Long
‘ 打开工作簿
Workbooks.Open (xls)
Set openWb = Workbooks(ActiveWorkbook.Name)
With openWb.Sheets(xlsCommonSheet)
.Select
lastRowx = lastRow()
If lastRowx > Then
.Rows(startRowCopy &”:” & lastRow).Copy _
thisWb.Sheets(combinedSheet).Range(“A” & pastePtr)
pastePtr = pastePtr + (lastRowx -startRowCopy) + 1
‘ 导入数据的工作簿名
importPtr = importPtr + 1
thisWb.Sheets(importedSheet).Range(“A”& importPtr) = openWb.Name
End If
End With
‘ 关闭工作簿
Workbooks(openWb.Name).CloseSaveChanges:=False
End Sub
Private Function lastRow() AsLong
lastRow =
If WorksheetFunction.CountA(Cells) > Then
‘按行向后搜索
lastRow =Cells.Find(What:=”*”, After:=[a1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
End If
End Function
Private Sub resetDefault()
‘ 重置应用程序屏幕刷新和计算模式
Application.ScreenUpdating = True
Application.Calculation =xlCalculationAutomatic
End Sub
运行main过程,弹出如下所示的对话框 。

excel图表怎么合并多个工作簿中的数据


选择“是”按钮,弹出如下所示的选择文件对话框 。
excel图表怎么合并多个工作簿中的数据


导入到要合并的工作簿所在的文件夹,选择要合并的工作簿文件,单击“打开”按钮 。如果一切顺利,则合并数据完成,并弹出如下所示的信息 。
excel图表怎么合并多个工作簿中的数据


我们可以查看结果 。在“导入工作簿名”工作表中,列出了已经合并数据的工作簿名,如下所示 。
excel图表怎么合并多个工作簿中的数据


在“合并工作表”工作表中,是合并后的数据,如下所示 。
【excel图表怎么合并多个工作簿中的数据】
excel图表怎么合并多个工作簿中的数据


猜你喜欢