VBA Excel Import Data From a Workbook To Another

Learn more about Excel and VBA

Import data from workbook to another

More examples here

A simple way to import or copy data from a closed book ("Livro1") for the active workbook ("Livro2"), given a set of conditions.

This example shows how we can import or copy data from one workbook to another without requiring the use of copy and paste.
Simply put this code in a VBA module and run the macro. We can also associate the macro to a button, allowing the execution of the process through a single click.

VB Code

Sub ImportData()
Workbooks.Open Filename:="C:\...\Livro1.xls"
Dim Origem As Worksheet
Dim Destino As Worksheet
Set Origem = Workbooks("Livro1.xls").Worksheets("Folha1")
Set Destino = Workbooks("Livro2.xls").Worksheets("Folha1")
k_linhas = 0
For rw = 11 To k_linhas
If Origem.Cells(rw, 1).Value > 0 And Origem.Cells(rw, 5) > 0 And Destino.Cells(rw, 17).Value =_
_Origem.Cells(rw, 1).Value Then
Destino.Cells(rw, 17).Value = Origem.Cells(rw, 1).Value
k_linhas = k_linhas + 1
End If
Next rw
Workbooks("Livro1.xls").Close SaveChanges:=False
MsgBox "Done!"
End Sub

Excel is part of my daily work routines. Almost every day, I create new spreadsheets with macros and new templates to meet the needs and requirements of quality management, budgeting and management of health and safety at work. This is my role for many years.
This purpose is simply to share my knowledge in some areas related to my work, in particular the creation of macros in Excel. Many of the examples are trivial but also many of the questions that are presented by my colleagues and friends are equally basic. I hope to be modestly useful.

Comments 1 comment

Kumarapush 2 years ago

Thanks for this article. The explanation is simple and also useful on importing data from another workbook.

Apart from VBA, Data can be pulled into an excel from another excel through External reference or through Data Import facility. For more info on these techniques, refer

http://officetricks.com/different-methods-to-impor...

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working