+ Reply to Thread
Results 1 to 3 of 3

Paste Failed

  1. #1
    Nathan Bell
    Guest

    Paste Failed

    All, I have this code and I cannot find out why it will not paste. I am
    getting the following error when trying to run this macro "Runtime Error
    1004: Paste method of worksheet class failed." Here is the code that I am
    trying to run:

    Sheets("CNP").Select
    Columns("A:Z").Select
    Selection.Delete Shift:=xlToLeft
    Range("A1").Select
    ActiveSheet.Paste
    Range("E:N,P:V,X:AC").Select
    Selection.Delete Shift:=xlToLeft
    Range("A1:F82").Select
    Selection.Copy
    Sheets("Daily").Select
    Range("A2:F82").Select
    Selection.ClearContents
    Range("A2").Select
    ActiveSheet.Paste
    Range("A6:F83").Select
    Application.CutCopyMode = False
    Selection.Sort Key1:=Range("F5"), Order1:=xlDescending, Header:=xlGuess,
    _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    Sheets("CNP").Select
    Columns("B:E").Select
    Selection.Delete Shift:=xlToLeft
    Range("A:B").Select
    Selection.Copy
    Sheets("Data").Select
    Dim rFound As Range
    Set rFound = Sheet1.Cells.Find("*", _
    Sheet1.Cells(1, 1), , , xlByColumns, xlPrevious)
    If rFound Is Nothing Then
    Range("A:B").Select
    Else
    rFound.Offset(0, 1).Resize(1, 2).EntireColumn.Select
    End If
    ActiveSheet.Paste
    End Sub

    It is failing on the second paste for some reason and I cannot figure out
    why. Any help would be greatly appreciated.

    Nathan Bell



  2. #2
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Try replacing your few lines with this order:

    Range("E:N,P:V,X:AC").Select
    Selection.Delete Shift:=xlToLeft
    Sheets("Daily").Range("A2:F82").ClearContents
    Sheets("CNP").Range("A1:F82").Copy
    Sheets("Daily").Select
    Range("A2").Select
    ActiveSheet.Paste

    What was happening is since you were clearing contents of cells after copying, but before pasting, the cells originally copied were no longer active.

  3. #3
    Don Guillett
    Guest

    Re: Paste Failed

    Gotta copy something before you can paste. Also, remove selections.

    Sheets("CNP").Select
    > Columns("A:Z").Select
    > Selection.Delete Shift:=xlToLeft
    > Range("A1").Select
    > ActiveSheet.Paste

    ============
    Range("A1:F82").Copy Sheets("Daily").Range("A2")


    --
    Don Guillett
    SalesAid Software
    [email protected]
    "Nathan Bell" <[email protected]> wrote in message
    news:[email protected]...
    > All, I have this code and I cannot find out why it will not paste. I

    am
    > getting the following error when trying to run this macro "Runtime Error
    > 1004: Paste method of worksheet class failed." Here is the code that I am
    > trying to run:
    >
    > Sheets("CNP").Select
    > Columns("A:Z").Select
    > Selection.Delete Shift:=xlToLeft
    > Range("A1").Select
    > ActiveSheet.Paste
    > Range("E:N,P:V,X:AC").Select
    > Selection.Delete Shift:=xlToLeft
    > Range("A1:F82").Select
    > Selection.Copy
    > Sheets("Daily").Select
    > Range("A2:F82").Select
    > Selection.ClearContents
    > Range("A2").Select
    > ActiveSheet.Paste
    > Range("A6:F83").Select
    > Application.CutCopyMode = False
    > Selection.Sort Key1:=Range("F5"), Order1:=xlDescending,

    Header:=xlGuess,
    > _
    > OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    > Sheets("CNP").Select
    > Columns("B:E").Select
    > Selection.Delete Shift:=xlToLeft
    > Range("A:B").Select
    > Selection.Copy
    > Sheets("Data").Select
    > Dim rFound As Range
    > Set rFound = Sheet1.Cells.Find("*", _
    > Sheet1.Cells(1, 1), , , xlByColumns, xlPrevious)
    > If rFound Is Nothing Then
    > Range("A:B").Select
    > Else
    > rFound.Offset(0, 1).Resize(1, 2).EntireColumn.Select
    > End If
    > ActiveSheet.Paste
    > End Sub
    >
    > It is failing on the second paste for some reason and I cannot figure out
    > why. Any help would be greatly appreciated.
    >
    > Nathan Bell
    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1