Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Johan Parlevliet
 
Posts: n/a
Default help needed with copy from one workbook to another

I am trying to copy things without using Windows("name").Activate

Workbooks(Orig_NameWB).Worksheets(Orig_NameWS).Ran ge(Cells(Line_No,
1), Cells(Line_No, 6)).Copy _
Destination:=Workbooks(New_NameWB).Worksheets(New_ NameWS).Range(Cells(New_Line_No,
1), Cells(New_Line_No, 6))

But this gives an error 1004 and I do not see what I am doing wrong
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

Unqualified range objects in general modules refer to the activesheet.

So this:

Workbooks(Orig_NameWB).Worksheets(Orig_NameWS).Ran ge( _
Cells(Line_No, 1), Cells(Line_No, 6)).Copy

could be rewritten as this:

Workbooks(Orig_NameWB).Worksheets(Orig_NameWS).Ran ge( _
Workbooks(Orig_NameWB).Worksheets(Orig_NameWS).Cel ls(Line_No,1), _
Workbooks(Orig_NameWB).Worksheets(Orig_NameWS).Cel ls(Line_No, 6)).Copy


But I'd use a couple of variables to make typing a little easier:

dim fRng as range
dim tRng as range

with Workbooks(Orig_NameWB).Worksheets(Orig_NameWS)
set frng = .Range(.Cells(Line_No, 1), .Cells(Line_No, 6))
end with

with Workbooks(New_NameWB).Worksheets(New_NameWS)
set trng = .Cells(New_Line_No,1)
end with
'excel will expand the single cell range to match the From Range.

fRng.copy _
destination:=tRng

========
Notice the extra dots in front of .cells. This means that they belong to the
previous with statement object.

If that doesn't work, I'd check each of those variables to see if they were what
I really expected.




Johan Parlevliet wrote:

I am trying to copy things without using Windows("name").Activate

Workbooks(Orig_NameWB).Worksheets(Orig_NameWS).Ran ge(Cells(Line_No,
1), Cells(Line_No, 6)).Copy _
Destination:=Workbooks(New_NameWB).Worksheets(New_ NameWS).Range(Cells(New_Line_No,
1), Cells(New_Line_No, 6))

But this gives an error 1004 and I do not see what I am doing wrong


--

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 COLUMN from 1 worksheet to another (in a different workbook) DavidB Excel Discussion (Misc queries) 3 January 15th 05 02:47 PM
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
Stubborn toolbars in Excel 007 Excel Discussion (Misc queries) 9 December 11th 04 02:02 PM
copy worksheet from closed workbook to active workbook using vba mango Excel Worksheet Functions 6 December 9th 04 07:55 AM


All times are GMT +1. The time now is 08:44 AM.

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"