How to import data from different excel files and

2020-08-01 06:17发布

I have different excel files which have multiple sheets that I would like to import into one main excel file. These files are under different directories. And so I'm wondering if it's feasible to import specific cells from all these files into one main excel file which should be updated at every change.

标签: excel import
4条回答
Summer. ? 凉城
2楼-- · 2020-08-01 06:46

You can create a macro like this:

Sub ConsolidateWorkbooks()
    Dim myRange As String
    myRange = "A1:B2" 'Put the range you want to copy from each workbook here
    Dim thisWorkbook As String
    Dim thisWorksheet As String
    thisWorkbook = ActiveWorkbook.name
    thisWorksheet = ActiveSheet.name

    CopyPasteOneWorkbook ("C:\firstworkbook.xls")
    CopyPasteOneWorkbook ("C:\secondworkbook.xls")


End Sub

Sub CopyPasteOneWorkbook(name As String)
    Workbooks.Open Filename:=name
    range(myRange).Select
    Application.CutCopyMode = False
    Selection.Copy
    Windows(thisWorkbook).Activate
    'Select the first empty cell in column A:
    Worksheets(thisWorksheet).range("A1").End(xlDown).Select
    Selection.Offset(1, 0).Select
    ActiveSheet.Paste
End Sub

If your workbooks are all in one file and have sequential names (workbook1.xls, workbook2.xls, etc.), then you can create a For loop. Otherwise, just put as many calls to CopyPasteOneWorkbook as you need.

查看更多
We Are One
3楼-- · 2020-08-01 06:56

use the following:

=('NAME_OF__SHEET'!A1)

NAME_OF__SHEET = "the name of your sheet" A1 = column, row

and your done!

查看更多
贼婆χ
4楼-- · 2020-08-01 07:12

http://www.rondebruin.nl/win/addins/rdbmerge.htm

This is a great macro/add-in to import all files in folder and if you want sub-folder into one spreadsheet.

查看更多
爷、活的狠高调
5楼-- · 2020-08-01 07:12

Regarding the second part of this question (including data from cells in other documents to your document), the answer is here:

https://superuser.com/questions/835940/import-one-cell-of-data-from-one-spreadsheet-to-another

查看更多
登录 后发表回答