Copying Of Data Not Working

John Davis

Well-known Member
Joined
Sep 11, 2007
Messages
3,457
Hello All:

I have the code below it's not working. Can anyone provide any input why this is not doing what it is supposed to do?


Workbooks.Open Filename:="D:\Common\data\IBMmain\OCEAN-BP.xls"
Rows("1:1").Delete
Workbooks.Open Filename:="D:\Common\data\IBMmain\OCEAN-HEADER.xls"
Rows("1:5").Copy
Windows("OCEAN-BP.xls").Activate
Rows("1:5").Select
ActiveSheet.Paste
ActiveWorkbook.Close
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Something like this perhaps?
Code:
Dim wbDst As Workbook
Dim wbSrc As Workbook
Set wbDst = Workbooks.Open(Filename:="D:\Common\data\IBMmain\OCEAN-BP.xls")
wbDst.ActiveSheet.Rows("1:1").Delete
Set wbSrc = Workbooks.Open(Filename:="D:\Common\data\IBMmain\OCEAN-HEADER.xls")
wbDst.ActiveSheet.Rows("1:5").Copy wbDst.ActiveSheet.Range("A1")
wbSrc.Close
 
Upvote 0
Something like this perhaps?
Code:
Dim wbDst As Workbook
Dim wbSrc As Workbook
Set wbDst = Workbooks.Open(Filename:="D:\Common\data\IBMmain\OCEAN-BP.xls")
wbDst.ActiveSheet.Rows("1:1").Delete
Set wbSrc = Workbooks.Open(Filename:="D:\Common\data\IBMmain\OCEAN-HEADER.xls")
wbDst.ActiveSheet.Rows("1:5").Copy wbDst.ActiveSheet.Range("A1")
wbSrc.Close

Norie:

For some reason this code is not working. I'm trying to get the first 5 row of OCEAN-HEADER to COPY to OCEAN-BP??
 
Upvote 0
John

That was untested 'air' code based on what you posted.

In what way does it not work?

Does it error?

Does it do nothing?

One problem I see is that there are no worksheet references in the original code, that's why I added ActiveSheet.
 
Upvote 0
John

That was untested 'air' code based on what you posted.

In what way does it not work?

Does it error?

Does it do nothing?

One problem I see is that there are no worksheet references in the original code, that's why I added ActiveSheet.


It doesn't error. It just doesn't copy the data into OCEAN-BP.
 
Upvote 0
My bad I think.:oops:

As I said untested.
Code:
wbSrc.ActiveSheet.Rows("1:5").Copy wbDst.ActiveSheet.Range("A1")
And the use of Activate/Select in the original code actually makes it hard to follow what's going on.:)
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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