Solved

Copy Data from another workbook via VBA

Posted on 2010-11-11
1
498 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

22 Experts available now in Live!

Get 1:1 Help Now