ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Paste works sometimes? (https://www.excelbanter.com/excel-programming/333995-re-paste-works-sometimes.html)

Tom Ogilvy

Paste works sometimes?
 
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

--
Regards,
Tom Ogilvy


"Craigm" wrote in
message ...

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

It always copies and pastes the correct filtered data. It may have
something to do with the filter being on or off before the routine is
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")
--------------------------------------


--
Craigm
------------------------------------------------------------------------
Craigm's Profile:

http://www.excelforum.com/member.php...o&userid=24381
View this thread: http://www.excelforum.com/showthread...hreadid=385573





All times are GMT +1. The time now is 01:58 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com