我对此有类似的问题:Combine 2 Excel tables into one appending the data?
但是,我对表不感兴趣,但对工作表中的列不感兴趣。
如果我有以下2个工作表:
我想要第三张纸,像这样:
如何从原始的两个工作表中创建第三个工作表?如果我在前两个工作表之一中添加一行,那么第三个工作表会自动更新吗?
答案 0 :(得分:5)
对两张纸执行以下步骤。
From Table
。单击确定。Close & Load to
。在“加载到”对话框中,选择Only Create Connection
,然后单击“加载”。在完成两个工作表之后,现在您应该在“工作簿查询”窗格中看到以下两个查询。
您现在有了想要的表。在向Table1和/或Table2添加行之后,当您单击“数据”选项卡上的“刷新”按钮时,新表Append1将更新。
答案 1 :(得分:0)
太棒了,如果你曾经运行过一个宏,否则你可以第一次尝试。
用于将多个 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
来源 https://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
来源 https://www.extendoffice.com/documents/excel/5017-excel-collect-data-from-multiple-sheets.html