Solved

Copy Data from another workbook via VBA

Posted on 2010-11-11
1
535 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

628 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