Using Paste Feature with out Activating Sheet

G

Guest

I am trying to copy a row from one sheet based on a certain criteria and then
copy it to another sheet. The below code works fine, but it take quite a
while to run through a couple thousand rows. I am trying to write the code
to just paste the row in the correct spot from the original sheet and not
activate the target sheet. Is this possible? The bottom case is code is my
feeble attempt... new to VBA

WORKING CODE - BUT SLOW
Case Is = "ALASK"
ActiveCell.EntireRow.Select
Selection.copy
Sheets("Alaska Option").Select
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste

DESIRED CODE - DOESN'T WORK!
Case Is = "ALASK"
ActiveCell.EntireRow.copy
Sheets("Alaska Option").Range("A1").End(xlDown).Offset(1, 0).Paste

Thanks,
Adam
 
G

Guest

Give this a wirl...

Case Is = "ALASK"
ActiveCell.EntireRow.copy _
Sheets("Alaska Option").Cells(rows.count, "A").end(xlup).offset(1,0)
 
S

stjori

I am trying to copy a row from one sheet based on a certain criteria and then
copy it to another sheet. The below code works fine, but it take quite a
while to run through a couple thousand rows. I am trying to write the code
to just paste the row in the correct spot from the original sheet and not
activate the target sheet. Is this possible? The bottom case is code is my
feeble attempt... new to VBA

WORKING CODE - BUT SLOW
Case Is = "ALASK"
ActiveCell.EntireRow.Select
Selection.copy
Sheets("Alaska Option").Select
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste

DESIRED CODE - DOESN'T WORK!
Case Is = "ALASK"
ActiveCell.EntireRow.copy
Sheets("Alaska Option").Range("A1").End(xlDown).Offset(1, 0).Paste

Thanks,
Adam

Are you trying to paste below the last used cell in column A? If so,
try Sheets("Alaska Option").Range("A65536").End(xlUp).Offset(1,
0).Paste
 
G

Guest

try:

ActiveCell.EntireRow.Copy Destination:=Sheets("Alaska
Option").Range("A1").End(xlDown).Offset(1, 0)
 
S

stjori

Does the _ after copy denote that the destination follows?

Thanks,
Adam

The _ is just a line break. After copy you can just have a space and
then the destination, or you can add Destination:= as in Vergel's
post. Pity this place doesn't have proper code tags.
 
G

Guest

Yup. The underscore character is just a line continuation. That allowed me to
post code on the forum that you could just cut and paste without having to
worry about text wrapping. It also makes the code look a little better in the
code window as the entire line will be visible...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top