Paste works sometimes?

C

Craigm

The code below runs sometimes then it crashes other times with a "Past
Method of Worksheet Class Failed". The Debugger stops on th
"ActiveSheet.Paste" line.

It always copies and pastes the correct filtered data. It may hav
something to do with the filter being on or off before the routine i
run??? Thats a guess.

I've tried to fix this so may ways I can't think anymore.

Any ideas? Thanks!

----------------------------------------
ActiveWindow.Visible = False
Windows("060631 Charts_DataDown.xls").Activate
Sheets("Datadown").Select
Rows("7:7").Select
Range("J7").Activate
Selection.AutoFilter
ActiveWindow.LargeScroll ToRight:=1
Selection.AutoFilter Field:=13, Criteria1:=">12/31/2004"
Operator:=xlAnd _
, Criteria2:="<1/1/2006"
Cells.Select
Selection.Copy

Sheets("2005").Select
Worksheets("2005").Activate

ActiveSheet.Paste Destination:=Worksheets("2005").Range("A1")
 
T

Tom Ogilvy

I assume neither the source or destination contain merged cells and neither
is protected. You might try

Dim obj as Window
set obj = ActiveWindow
ActiveWindow.Visible = False
Windows("060631 Charts_DataDown.xls").Activate
Sheets("Datadown").Select
Rows("7:7").Select
Range("J7").Activate
Selection.AutoFilter
ActiveWindow.LargeScroll ToRight:=1
Selection.AutoFilter Field:=13, Criteria1:=">12/31/2004",
Operator:=xlAnd _
, Criteria2:="<1/1/2006"
Cells.Select
Selection.Copy

obj.visible = True
obj.Activate
Sheets("2005").Select
Worksheets("2005").Activate
Range("A1").Select
ActiveSheet.Paste
 

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