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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
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,213,527
Messages
6,114,150
Members
448,552
Latest member
WORKINGWITHNOLEADER

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