Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / February 2006

Tip: Looking for answers? Try searching our database.

how do import data from two sheets into one

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
vbidiot - 22 Feb 2006 22:09 GMT
I'm trying to figure out the easiest way to do this.
I want two copy a set of data from two different workbooks and merge it

together into one workbook.

Book1   Data1
Book2   Data2

Merge book1 and book2 into book3.

I've created a button in book3 to pull the data from book1 and book2.
I've tried several different ways but it's a bit messy. I was wondering
if there is a simple code for it.

thanks!

Signature

vbidiot

Edwin Tam - 23 Feb 2006 02:45 GMT
Try to code below. Note that:
1) The macro will clear the cells in the target worksheet first (in book3)
2) I assume the 2 data lists have the same columns
3) The macro expects the 2 data lists have the same column headings, and it
will only copy the column headings of the 1st data list.

Sub copy_data()
Dim tmp As Single
Dim target_sheet As Object
Set target_sheet = ThisWorkbook.Worksheets("Sheet1")
target_sheet.Cells.Clear
Workbooks("Book1").Worksheets("Sheet1").Range("A1").CurrentRegion.Copy _
   target_sheet.Range("A1")
tmp = target_sheet.Range("A1").CurrentRegion.Rows.Count
With Workbooks("Book2").Worksheets("Sheet1").Range("A1").CurrentRegion
   .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count).Copy _
       target_sheet.Range("A1").Range("A1").Offset(tmp, 0)
End With
End Sub

Regards,
Edwin Tam
support@vonixx.com
http://www.vonixx.com

> I'm trying to figure out the easiest way to do this.
> I want two copy a set of data from two different workbooks and merge it
[quoted text clipped - 11 lines]
>
> thanks!
vbidiot - 24 Feb 2006 00:20 GMT
I keep getting an error message but I think it is because of how I'm
putting in the files to pull.

my book 1 is P:/project/table
my book 2 is P:/project/table2

What am I doing wrong??

the file that I want to pull to is:

p:/import

Signature

vbidiot

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.