need Macro to copy from one workbook to another

Revathi

New Member
Joined
May 26, 2015
Messages
34
Hi all,



Example : I need to copy the data from the workbook 1 from the sheet data and paste it in the workbook 2 to the sheet raw wherein the sheet "raw" already have some data but i need to paste these new data to the below on those old data.

Please assist on this.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
is workbook1 already open?
is workbook2 already open?
in workbook1 are headers in row 1 and does data to be copied start in row 2?
in workbook1 does column A have data in every row? (need to find last used row - can column A be used?)
 
Last edited:
Upvote 0
try this ...

assumes
- both workbook are open
- headers are in row1\ data starts in A2
- last entry in column A marks last row

amend
- last column (currently A to T are copied)
- workbook names & extensions to match actual names

Code:
Sub CopyData()
    Const LastColumn = "[COLOR=#ff0000]T[/COLOR]"
    Dim sh As Worksheet, cel As Range, rng As Range
    Set sh = Workbooks("[COLOR=#ff0000]wb1Name.xlsx[/COLOR]").Sheets("data")
    Set cel = Workbooks("[COLOR=#ff0000]wb2Name.xlsx[/COLOR]").Sheets("raw").Range("A" & Rows.Count).End(xlUp).Offset(1)
    Set rng = sh.Range("A2", sh.Range("A" & Rows.Count).End(xlUp)).Resize(, Range(LastColumn & 1).Column)
    rng.Copy cel
End Sub
 
Upvote 0
HI Yongle,

I am getting a bug called subscript out of range. Below is my requirement with clear points.

> Both the workbooks are already opened
> I need to copy the data which is available in workbook 2 in yyy sheet without headers and i need to paste the same in workbook 1 in xxx sheet at A348980 cell.. however every week this range will change.
> Please help how do i need to paste the data at the bottom of the details available in Workbook 1.
 
Upvote 0

Forum statistics

Threads
1,216,100
Messages
6,128,825
Members
449,470
Latest member
Subhash Chand

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