如何提取EXCEL表中数据,汇总到一张表内?
发布网友
发布时间:2022-02-27 13:36
我来回答
共4个回答
热心网友
时间:2022-02-27 15:05
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet1 As Excel.Worksheet
Dim strFolder As String
Dim MyFile As String
Dim js As Integer
'打开选择文件夹对话框
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select Folder"
.InitialFileName = "d:\"
If .Show Then
strFolder = .SelectedItems(1)
End If
End With
If strFolder = "" Then Exit Sub
js = 1 '循环当总表序号
MyFile = Dir(strFolder & "*.xls") '第一个文件路径
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(strFolder & MyFile)
Set xlSheet1 = xlBook.Worksheets(1)
'此处填写开始将表数据填入汇总表
Sheet1.Cells(js + 1, 1) = js
Sheet1.Cells(js + 1, 2) = xlSheet1(1, 1) '给你一个示例Sheet1.Cells(js + 1, 2) 是总表第二行第二列位置,xlSheet1(1, 1)其他表的姓名行列
xlApp.SaveWorkspace
xlApp.Quit
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet1 = Nothing
'上面一段是第一个文件下面是开始循环填表处一样
Do While MyFile <> "" '循环其他文件路径
js = js + 1
MyFile = Dir
If MyFile = "" Then
Exit Do
End If
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(strFolder & MyFile)
Set xlSheet1 = xlBook.Worksheets(1)
'此处填写开始将表数据填入汇总表
Sheet1.Cells(js + 1, 1) = js
Sheet1.Cells(js + 1, 2) = xlSheet1(1, 1) '给你一个示例Sheet1.Cells(js + 1, 2) 是总表第二行第二列位置,xlSheet1(1, 1)其他表的姓名行列
xlApp.SaveWorkspace
xlApp.Quit
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet1 = Nothing
Loop追问看不懂具体怎么用/尴尬😓
追答你是一点基础都没有啊,这我很难帮你啊!把总表和其他表各发一个给我私我
热心网友
时间:2022-02-27 16:23
可以建立新的沟通渠道上传文件。私信我或评论后我私信你。代码处理不免费。
热心网友
时间:2022-02-27 17:58
解决问题需要付费。可以吗?
热心网友
时间:2022-02-27 19:49
写代码可以处理