我有一个类似的问题:Combine 2 Excel tables into one appending the data?
如果我有以下 2 个工作表:
我想有第三个表,看起来像:
如果我在前两个工作表中添加一行,第三个工作表会自动更新吗?
对这两个工作表执行以下过程。
在其中一列中选择一个值。
转到数据选项卡,然后在获取和转换组中选择From Table
。单击确定。
在查询编辑器中,从下拉菜单中选择Close & Load to
在主页选项卡上关闭并加载。在加载到对话框中,选择Only Create Connection
并单击加载。
在对这两个工作表执行此操作之后,您现在应该在“工作簿查询”窗格中看到以下两个查询。
右键单击 Table1 查询并选择 Append。在底部的下拉框中选择 Table2。单击 OK。
在查询编辑器中,单击关闭 & amp;加载(图标,而不是下拉菜单)。
您现在有了所需的表。向 Table1 和 / 或 Table2 添加行后,当您单击 Data-tab 上的 Refresh 按钮时,新表 Append1 将更新。
它的奇妙,如果你有甚至一次运行一个宏,否则你可以尝试第一次。
在顶行单击 & gt;& gt;developer
在最左上方单击 & gt;& gt;visual basic
右键单击左上方列的文件名 & gt;& gt;插入模块
粘贴以下代码,保存并运行(播放绿色三角形)。
用于在一个 excel 文件中组合多个 excel 文件不同的选项卡
Sub mergeExcelFiles()
'Merges all files in a folder to a main file.
'Define variables:
Dim numberOfFilesChosen, i As Integer
Dim tempFileDialog As fileDialog
Dim mainWorkbook, sourceWorkbook As Workbook
Dim tempWorkSheet As Worksheet
Set mainWorkbook = Application.ActiveWorkbook
Set tempFileDialog = Application.fileDialog(msoFileDialogFilePicker)
'Allow the user to select multiple workbooks
tempFileDialog.AllowMultiSelect = True
numberOfFilesChosen = tempFileDialog.Show
'Loop through all selected workbooks
For i = 1 To tempFileDialog.SelectedItems.Count
'Open each workbook
Workbooks.Open tempFileDialog.SelectedItems(i)
Set sourceWorkbook = ActiveWorkbook
'Copy each worksheet to the end of the main workbook
For Each tempWorkSheet In sourceWorkbook.Worksheets
tempWorkSheet.Copy after:=mainWorkbook.Sheets(mainWorkbook.Worksheets.Count)
Next tempWorkSheet
'Close the source workbook
sourceWorkbook.Close
Next i
End Sub
Sourcehttps://professor-excel.com/merge-sheets/
用于在同一 excel 文件的一个选项卡中合并不同的选项卡
Sub mergeExcelTabs()
'UpdatebyExtendoffice20180205
Dim I As Long
Dim xRg As Range
On Error Resume Next
Worksheets.Add Sheets(1)
ActiveSheet.Name = "Combined"
For I = 2 To Sheets.Count
Set xRg = Sheets(1).UsedRange
If I > 2 Then
Set xRg = Sheets(1).Cells(xRg.Rows.Count + 1, 1)
End If
Sheets(I).Activate
ActiveSheet.UsedRange.Copy xRg
Next
End Sub
Sourcehttps://www.extendoffice.com/documents/excel/5017-excel-collect-data-from-multiple-sheets.html
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(83条)