+ Reply to Thread
Results 1 to 4 of 4

Run time error 1004 - PasteSpecial of Range class failed

  1. #1
    Registered User
    Join Date
    01-23-2012
    Location
    Essex UK
    MS-Off Ver
    Excel 2007
    Posts
    2

    Run time error 1004 - PasteSpecial of Range class failed

    Hi this is my first ever post... quite new to this coding lark

    coding up Excel 2007 and I'm having problems with this error. Firs time it works, second time it fails, third time it works, fourth time it fails... see the pattern! Trying to copy from one workbook to another then move to next clear line and paste next value

    Can find a way round it anyone help PLEASE

    Private Sub OpenOneFile()
    Dim fn As Variant
    Dim LR As Long
    Dim n As Long

    n1 = 0
    n = 0

    fn = Application.GetOpenFilename("Excel-files,*.xlsx", _
    1, "Select One File To Open", , False)
    'If TypeName(fn) = "Boolean" Then Exit Sub

    ' the user didn't select a file
    Debug.Print "Selected file: " & fn
    Workbooks.Open fn

    'Sync Windows
    Windows.CompareSideBySideWith "MASTER.xlsm"
    Windows.SyncScrollingSideBySide = False

    '----------------------------------------------------------------------------------
    Windows("RFI_Template.xlsx").Activate
    Range("M6").Copy
    Windows("MASTER.xlsm").Activate
    Sheets("RFI Log").Select
    'Unprotect
    ActiveSheet.Unprotect Password:="window"
    n1 = Range("H3").Value
    n = 6 + n1
    Cells(n, 2).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False (FAILS HERE EVERY 2nd ATTEMPT)
    '----------------------------------------------------------------------------------
    Windows("RFI_Template.xlsx").Activate
    Range("M7").Copy
    Windows("MASTER.xlsm").Activate
    Cells(n, 3).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    '----------------------------------------------------------------------------------
    Windows("RFI_Template.xlsx").Activate
    Range("m10").Copy
    Windows("MASTER.xlsm").Activate
    Cells(n, 4).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    '----------------------------------------------------------------------------------
    Windows("RFI_Template.xlsx").Activate
    Range("d12").Copy
    Windows("MASTER.xlsm").Activate
    Cells(n, 6).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    '----------------------------------------------------------------------------------
    Windows("RFI_Template.xlsx").Activate
    Range("b16").Copy
    Windows("MASTER.xlsm").Activate
    Cells(n, 8).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    '----------------------------------------------------------------------------------
    Range("F2").Copy
    Cells(n, 7).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    '----------------------------------------------------------------------------------
    n1 = 0
    n = 0
    'Range("p1") = 0

    'Close RFI_Template window
    Windows("RFI_Template.xlsx").Activate
    ActiveWorkbook.Close False
    Windows("MASTER.xlsm").Activate
    Range("e6").Select

    'Protect Sheet
    Windows("MASTER.xlsm").Activate
    Sheets("RFI Log").Select
    ActiveSheet.Protect Password:="window", DrawingObjects:=True, Contents:=True, Scenarios:=True _
    , AllowSorting:=True, AllowFiltering:=True

    End Sub

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Run time error 1004 - PasteSpecial of Range class failed

    Welcome to the forum.

    Please attach the file that you use along with the above code so its easy to troubleshoot.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    01-23-2012
    Location
    Essex UK
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Run time error 1004 - PasteSpecial of Range class failed

    High and thanks for the help I think I have attached the file the folder goes on the desktop and has the template the the code uses. The master Nav Tab has the button to activate the copy and paste...

    Thanks again

    ps you will need to put the RFI Template into a folder called Master RFI and leave the Master on the desktop. Use the Master Nav Tab to activate
    Attached Files Attached Files

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Run time error 1004 - PasteSpecial of Range class failed

    I guess it would be better if you explain what you are trying to achieve through your code. You have used a lot of select & activate statements which can be eradicated. I can provide you an alternate code if you let me know what you want the code to do.

+ 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