Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Copy Data from another workbook via VBA

Posted on 2010-11-11
1
Medium Priority
?
539 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 2000 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

705 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