Data transfer between two workbooks

prathyush

Board Regular
Joined
Jan 9, 2009
Messages
60
I have two workbooks book1.xls and book2.xls

I want to load data in sheet1 of book2 to sheet1 of book1.
This sheet1 of book2 has a table of 10 rows and 10 columns.

How to do that in VBA??
 
It is just the syntax for specifying a named argument. Destination= will give an error.

Another example:

Rich (BB code):
Workbooks.Open Filename:=ThisWorkbook.Path & "\" & "Book2.xls"
Another improvement is needed..
In the above example since i know the no.of rows are 10 i gave it as Range("A1:E10")
Here i dont want to hardcode because it may change and i cannot keep on changing my formula.
Instead i want to copy till the blank row at the end..
how to do that??
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
If you want to copy everything try

Code:
Workbooks("Book2.xls").Sheets("Sheet1").UsedRange.Copy _
    Destination:=Workbooks("Book1.xls").Sheets("Sheet1").Range("A1")
 
Upvote 0
If you want to copy everything try

Code:
Workbooks("Book2.xls").Sheets("Sheet1").UsedRange.Copy _
    Destination:=Workbooks("Book1.xls").Sheets("Sheet1").Range("A1")
it works but it is copying entire data..
but my actual data starts from 5th row..i had some process related info in first four rows which is not required.
 
Upvote 0
Try

Code:
Workbooks("Book2.xls").Sheets("Sheet1").UsedRange.Offset(4).Copy _
    Destination:=Workbooks("Book1.xls").Sheets("Sheet1").Range("A1")
 
Upvote 0
here is my requirement

copy from 3 row 2nd column to nth row 5th column
here n is equal to empty row number - 1.dont the value of empty row number( i mean it will keep on changing)
 
Upvote 0
Try

Code:
Dim LR As Long
With Workbooks("Book2.xls").Sheets("Sheet1")
    LR = .Range("B" & Rows.Count).End(xlUp).Row
    .Range("B3:E" & LR).Copy _
    Destination:=Workbooks("Book1.xls").Sheets("Sheet1").Range("A1")
End With
 
Upvote 0
Try

Code:
Dim LR As Long
With Workbooks("Book2.xls").Sheets("Sheet1")
    LR = .Range("B" & Rows.Count).End(xlUp).Row
    .Range("B3:E" & LR).Copy _
    Destination:=Workbooks("Book1.xls").Sheets("Sheet1").Range("A1")
End With
What if E is also not fixed????I mean if it is nth column rather than 5th column??
 
Upvote 0
Try

Code:
Dim LR As Long, LC As Integer
With Workbooks("Book2.xls").Sheets("Sheet1")
    LR = .Cells(Rows.Count, "B").End(xlUp).Row
    LC = .Cells(3, Columns.Count).End(xlToLeft).Column
    .Range(.Cells(3, 2), .Cells(LR, LC)).Copy _
    Destination:=Workbooks("Book1.xls").Sheets("Sheet1").Range("A1")
End With
 
Upvote 0

Forum statistics

Threads
1,223,941
Messages
6,175,541
Members
452,652
Latest member
eduedu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top