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

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,358
Office Version
  1. 365
Platform
  1. Windows
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

John Davis

Well-known Member
Joined
Sep 11, 2007
Messages
3,457
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

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,358
Office Version
  1. 365
Platform
  1. Windows
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 Davis

Well-known Member
Joined
Sep 11, 2007
Messages
3,457
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

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,358
Office Version
  1. 365
Platform
  1. Windows
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,191,718
Messages
5,988,275
Members
440,146
Latest member
rgomes8

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
Top