Solved

Copy Data from another workbook via VBA

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
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.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

821 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