+ Reply to Thread
Results 1 to 3 of 3

Special Paste Error

Hybrid View

  1. #1
    Registered User
    Join Date
    03-25-2008
    Posts
    3

    Special Paste Error

    Can someone tell me why I am getting an error for the PasteSpecial line? It is error 1004 and reads: "PasteSpecial method of range class failed".

    Thanks!

    Sub Import()
        Dim FName As Variant
        Dim wb As Workbook, x As String
        FName = Application.GetOpenFilename _
        (filefilter:="Excel Files(*.xls),*.xls,All Files (*.*),*.*")
        If FName = False Then
             MsgBox "Please select a file!!"
            Exit Sub
        Else
        Workbooks.Open Filename:=FName
                    For Each wb In Workbooks
                If wb.Name <> ThisWorkbook.Name Then x = wb.Name
            Next wb
            Range("B3600").Select
            Selection.Copy
            Workbooks.Open Filename:="S:\Program Engineering\dieselspec.xls"
            Sheets("Data").Activate
            Range("H6").Select
            Selection.End(xlDown).Select
            ActiveCell.Offset(1, 0).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
            Application.DisplayAlerts = False
            ActiveWorkbook.Close
            Application.DisplayAlerts = True
        End If
    End Sub

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650
    Hi, Part of your code is shown below, you will see I've added a message Box, that will show you the range you have selected is the last row in the sheet, then your next bit of code shows an offset one down from there, which would be, I know not where !!This could possibly be your problem.
    I've not looked any further.
     Range("H6").Select
            Selection.End(xlDown).Select
            MsgBox Selection.Address
            ActiveCell.Offset(1, 0).Select
    Regards Mick

  3. #3
    Registered User
    Join Date
    03-25-2008
    Posts
    3
    Thanks for the reply.

    The problem actually turned out to be the file was protected. Problem solved!

+ 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