Solved

Copy Data from another workbook via VBA

Posted on 2010-11-11
1
511 Views
Last Modified: 2012-06-27
I need to copy all the data from a sheet in a closed workbook into a sheet in my open workbook.
Can someone point me in the direction of how to set this up in VBA code? I need to copy sheet1 from my file called "IVAL"  and paste values into my open file on the sheet called "IVAL".
0
Comment
Question by:Lawrence Salvucci
1 Comment
 
LVL 50

Accepted Solution

by:
Dave Brett earned 500 total points
ID: 34117346
Seeing sample data would help

This code should assist though. It goes into your open workbook

It will copy the usedrange of a sheet called Sheet1 from a workbook called IVAL stored under C\temp

<pls edit your path - the "c:\temp\ "and the "Sheet1" name as needed>

This usedrange is copied to the first cell under the last used cell in sheet IVAL from the host (your open) worknook

My article here - http://www.experts-exchange.com/A_2804.html - may also be of interest/use.

Cheers

Dave
Sub GetData()
    Dim Wb1 As Workbook
    Dim Wb2 As Workbook
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Dim rng1 As Range
    Set Wb1 = ThisWorkbook
    Set ws1 = ThisWorkbook.Sheets("IVAL")
    With Application
        .ScreenUpdating = False
        .EnableEvents = flase
    End With
    Set Wb2 = Workbooks.Open("C:\temp\IVAL.xls")
    Set ws2 = Wb2.Sheets("Sheet1")
    Set rng1 = ws1.Cells.Find("*", ws1.[a1], , , xlByRows, xlPrevious)
    ws2.UsedRange.Copy rng1.Offset(1, 0)
    Wb2.Close False
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now