PC Review


Reply
Thread Tools Rate Thread

Copy / Paste Errors

 
 
Swimmer
Guest
Posts: n/a
 
      9th Aug 2007
I have a workbook that copies data from another workbook into one
sheet. The data is taken into this sheet on the new workbook in the
raw format. When it is in the new workbook, I add an index, and copy
it to a new sheet, where it is formatted. The intention is that the
formatted sheet is updated, but you can see the updates on a sheet in
the original delivery format.
I`ve written three macros to do all this, and they seem to work fine
when called individually, but fail when called in sequence (they are
called in sequence on Workbook Open). I get a Paste Method of
Worksheet Class Failed (1004) error. Any idea why this is?

Code below:

Sub Copypasteinput()

Application.ScreenUpdating = False
Application.EnableEvents = False
Workbooks.Open Filename:= _
"\\............xls"
Application.EnableEvents = True
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Copy
Application.DisplayAlerts = False
ActiveWorkbook.Close
Sheets("Authorisecopy").Visible = True
Sheets("Authorisecopy").Select
Range("C1").Select
ActiveSheet.Paste
Range("C1").Select

End Sub

Sub AddIndex()
Range("A2").Select
Do Until ActiveCell.Offset(0, 2).Value = ""
ActiveCell.Value = ActiveCell.Offset(-1, 0) + 1
ActiveCell.Offset(1, 0).Select
Loop
End Sub

Sub CopytoDMDsort()

Set ws = Worksheets("DMDView")

' Select Data from AuthoriseCopy and copy to DMD View sheet
Sheets("Authorisecopy").Select
Range("A1").Select
Application.CutCopyMode = False
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Copy
Sheets("DMDView").Select
Sheets("Authorisecopy").Visible = False
Range("A1").Select
ActiveSheet.Paste Here is where the macro fails
Selection.Sort Key1:=Range("V2"), Order1:=xlDescending,
Key2:=Range("C2") _
, Order2:=xlAscending, Key3:=Range("D2"), Order3:=xlAscending,
Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom
' Find last row
iRow = ws.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
ws.Cells(iRow, 1).Select
Do
If ActiveCell.Offset(0, 22).Value = "No" Then
Selection.EntireRow.Delete
If ActiveCell.Offset(0, 22).Value = "" Then
Selection.EntireRow.Delete
ActiveCell.Offset(-1, 0).Select
Loop Until ActiveCell.Value = "1"
' Insert Subtotals
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Subtotal GroupBy:=2, Function:=xlCount,
TotalList:=Array(6), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
Range("A1").Value = "Index"
Application.ScreenUpdating = True

End Sub

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      9th Aug 2007

The 1st macro opens a workbook and closes it which changes the focus. You
need to activate the workbook before you continu.
"Swimmer" wrote:

> I have a workbook that copies data from another workbook into one
> sheet. The data is taken into this sheet on the new workbook in the
> raw format. When it is in the new workbook, I add an index, and copy
> it to a new sheet, where it is formatted. The intention is that the
> formatted sheet is updated, but you can see the updates on a sheet in
> the original delivery format.
> I`ve written three macros to do all this, and they seem to work fine
> when called individually, but fail when called in sequence (they are
> called in sequence on Workbook Open). I get a Paste Method of
> Worksheet Class Failed (1004) error. Any idea why this is?
>
> Code below:
>
> Sub Copypasteinput()
>
> Application.ScreenUpdating = False
> Application.EnableEvents = False
> Workbooks.Open Filename:= _
> "\\............xls"
> Application.EnableEvents = True
> Range("A1").Select
> Range(Selection, Selection.End(xlToRight)).Select
> Range(Selection, Selection.End(xlDown)).Copy
> Application.DisplayAlerts = False
> ActiveWorkbook.Close
> Sheets("Authorisecopy").Visible = True
> Sheets("Authorisecopy").Select
> Range("C1").Select
> ActiveSheet.Paste
> Range("C1").Select
>
> End Sub
>
> Sub AddIndex()
> Range("A2").Select
> Do Until ActiveCell.Offset(0, 2).Value = ""
> ActiveCell.Value = ActiveCell.Offset(-1, 0) + 1
> ActiveCell.Offset(1, 0).Select
> Loop
> End Sub
>
> Sub CopytoDMDsort()
>
> Set ws = Worksheets("DMDView")
>
> ' Select Data from AuthoriseCopy and copy to DMD View sheet
> Sheets("Authorisecopy").Select
> Range("A1").Select
> Application.CutCopyMode = False
> Range(Selection, Selection.End(xlToRight)).Select
> Range(Selection, Selection.End(xlDown)).Copy
> Sheets("DMDView").Select
> Sheets("Authorisecopy").Visible = False
> Range("A1").Select
> ActiveSheet.Paste Here is where the macro fails
> Selection.Sort Key1:=Range("V2"), Order1:=xlDescending,
> Key2:=Range("C2") _
> , Order2:=xlAscending, Key3:=Range("D2"), Order3:=xlAscending,
> Header:= _
> xlGuess, OrderCustom:=1, MatchCase:=False,
> Orientation:=xlTopToBottom
> ' Find last row
> iRow = ws.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
> ws.Cells(iRow, 1).Select
> Do
> If ActiveCell.Offset(0, 22).Value = "No" Then
> Selection.EntireRow.Delete
> If ActiveCell.Offset(0, 22).Value = "" Then
> Selection.EntireRow.Delete
> ActiveCell.Offset(-1, 0).Select
> Loop Until ActiveCell.Value = "1"
> ' Insert Subtotals
> Range(Selection, Selection.End(xlToRight)).Select
> Range(Selection, Selection.End(xlDown)).Select
> Selection.Subtotal GroupBy:=2, Function:=xlCount,
> TotalList:=Array(6), _
> Replace:=True, PageBreaks:=False, SummaryBelowData:=True
> Range("A1").Value = "Index"
> Application.ScreenUpdating = True
>
> End Sub
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy & Paste errors Travelers Lane Windows XP General 1 29th Jul 2008 02:17 PM
Excel 2007 - Conditional Formatting copy/paste errors Bob Microsoft Excel Discussion 2 11th Apr 2008 11:14 PM
How avoid errors when you Copy chartobjects paste in powerpoint Gunnar Johansson Microsoft Excel Programming 0 8th May 2005 12:40 PM
Re: So many errors. Javascript, copy & paste, svchost.exe ... PA Bear Windows XP Internet Explorer 0 15th Aug 2003 02:03 AM
Re: So many errors. Javascript, copy & paste, svchost.exe ... Frank Saunders, MS-MVP Windows XP Internet Explorer 0 15th Aug 2003 01:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:36 AM.