View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Mat P:son[_2_] Mat P:son[_2_] is offline
external usenet poster
 
Posts: 97
Default copy entire row to another workbook

Okay, let me try to figure this out now:

1) The code snippet you posted earlier, is that supposed to go into the
"support by project.xls" workbook?

2) You also start out on a sheet in the "support by project.xls" workbook
(not necessarily on the DATA sheet though)?

When I single-step through the code I get pretty odd results; e.g., how do
you know which cell is the ActiveCell of the "project request.xls" workbook?
And which sheet? That could be anything, right? If you have only one sheet it
should perhaps be all right, but you still wouldn't know which cell happens
to be the active one.

Maybe you have assumed that by iterating with E will automatically set the
ActiveCell? Regardless, I suggest you use for example the following simple
change:

Range(E, E.End(xlToRight)).Select

Also, the Paste() method failed for me. Again, the code relies heavily on
implicit objects, i.e., instead of saying for example
Worksheet("abc").Cells(blahblah) you just say Cells(blahblah). That's pretty
dangerous. Be explitic about which objects you're operating on.

You've got the following line:

Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Paste

- Cells returns all the cells on the active worksheet
- Rows gives you all the rows of the active worksheet
- ... And, well, there are 65536 of them, and your popping back up again,
and taking one step down. So far so good, I suppose, although it seems a
little bit unnecessary to me
- But what you get from Offset is a Range, and Ranges do not expose a Paste
method. I suppose you cactually meant ...Offset().Activate?

However, next time through the loop you try to access the next E. But in
order to do that you need to re-activate the source workbook again, otherwise
things will blow up in your face.

Anyhow, what we now end up with is something like this (and I eventually
reactivate the original workbook and -sheet, for good measure :-)

==================================

For Each E In UsedRng
If E.Value = BegDate Then
If E.Value <= EndDate Then

Range(E, E.End(xlToRight)).Select
Selection.Copy
Workbooks("support by project.xls").Activate

If ActiveSheet.Name < mySheet Then Sheets(mySheet).Activate

Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Activate
ActiveSheet.Paste

Workbooks("project request.xls").Activate
End If
End If
Next E

Workbooks("project request.xls").Activate
Sheets(mySheet).Activate

==================================

This was more or less the smallest incremental change I could do in order to
get your code working. Happy hacking! :-)

Cheers,
/MP


"Craig" wrote:

I don't get any prompts from excel, the error in vba is run time error
'1004' Method 'Range' of object '_Global' failed on the

If E.Value <= EndDate Then Range(E, ActiveCell.End(xlToRight)).Select

line