Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
DavidB
 
Posts: n/a
Default copy COLUMN from 1 worksheet to another (in a different workbook)

I have 2 WORKBOOKS - OLD and NEW

Each Workbook is identical but OLD has OLD data which I need to copy to NEW
workbook a sheet at a time. (about 40 sheets)

I'm trying to copy SELECTED columns from say Oldworkbook sheet 1 to
NewWorkbook Sheet 1 etc..

The following code works fine for Columns A:B for example
but if I do D:D or C:D I get and error!!!

Runtime error: -2147417848 (80010108)
Mehtod 'Copy' of object Range failed

WHY?? - all I've done is changed the column !!

Break shows error at sourceRange.Copy Destination:=destrange
at this point it has copied the 1st sheet

HELP!!!

Code:

Sub CopyColumn()
Dim newbook As Workbook
Dim oldbook As Workbook
Dim sourceRange As Range
Dim destrange As Range
Dim cnum As Integer
Dim sht As Long
Application.ScreenUpdating = False
Set newbook = ThisWorkbook
Set oldbook = Workbooks.Open("C:\DATA\OLD.XLS")
For skt = 1 To 3 'Sheets.Count - ok limit to 3 sheets for testing
Set sourceRange = oldbook.Worksheets(sht).Columns("D:D")
Set destrange = newbook.Worksheets(sht).Columns("D:D")
sourceRange.Copy Destination:=destrange
Next sht
oldbook.Close
Application.ScreenUpdating = True
End Sub


  #2   Report Post  
swisse
 
Posts: n/a
Default

David,
Are you sure your old workbook has at least 3 worksheets and that each of
them has a column D? Otherwise your code looks fine except for the line For
skt which should be For sht, which I think is only a typographical error.

Swisse


  #3   Report Post  
DavidB
 
Posts: n/a
Default

Thanks

Yes, actually the OLD workbook has about 40 worksheets and columns A-V are
populated !!

skt - is a typo !!

"swisse" wrote in message
...
David,
Are you sure your old workbook has at least 3 worksheets and that each of
them has a column D? Otherwise your code looks fine except for the line

For
skt which should be For sht, which I think is only a typographical error.

Swisse




  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

What happens if you do it manually?

I would have expected a different error (1004) if the "to" worksheet were
protected, though.

Same thing with merged cells.

Any chance that you have other code that's doing more stuff (maybe a worksheet
event?) and interfering with your code (resetting variables when you don't want
variables reset).

DavidB wrote:

I have 2 WORKBOOKS - OLD and NEW

Each Workbook is identical but OLD has OLD data which I need to copy to NEW
workbook a sheet at a time. (about 40 sheets)

I'm trying to copy SELECTED columns from say Oldworkbook sheet 1 to
NewWorkbook Sheet 1 etc..

The following code works fine for Columns A:B for example
but if I do D:D or C:D I get and error!!!

Runtime error: -2147417848 (80010108)
Mehtod 'Copy' of object Range failed

WHY?? - all I've done is changed the column !!

Break shows error at sourceRange.Copy Destination:=destrange
at this point it has copied the 1st sheet

HELP!!!

Code:

Sub CopyColumn()
Dim newbook As Workbook
Dim oldbook As Workbook
Dim sourceRange As Range
Dim destrange As Range
Dim cnum As Integer
Dim sht As Long
Application.ScreenUpdating = False
Set newbook = ThisWorkbook
Set oldbook = Workbooks.Open("C:\DATA\OLD.XLS")
For skt = 1 To 3 'Sheets.Count - ok limit to 3 sheets for testing
Set sourceRange = oldbook.Worksheets(sht).Columns("D:D")
Set destrange = newbook.Worksheets(sht).Columns("D:D")
sourceRange.Copy Destination:=destrange
Next sht
oldbook.Close
Application.ScreenUpdating = True
End Sub


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy a workbook from other workbook with lot of sheets wit... Vai Excel Discussion (Misc queries) 1 January 3rd 05 10:27 PM
How can I save an editable copy of a protected excel workbook? randyice Excel Discussion (Misc queries) 1 December 23rd 04 09:01 PM
how to copy 2350 hyperlink full paths to any column in a worksheet ? kontiki Excel Discussion (Misc queries) 4 December 10th 04 10:00 PM
How do I copy page setup from one worksheet & paste into new shee. Rasc0 Excel Discussion (Misc queries) 2 December 1st 04 10:12 PM
how can I duplicate or copy a workbook then divide selected cells. macros excel... duplication and calculat Excel Discussion (Misc queries) 1 November 29th 04 03:16 PM


All times are GMT +1. The time now is 01:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"