Solved

Paste Special Error message -RUN TIME ERROR 1004 PASTE SPECIAL METHOD OF RANGE CLASS FAILED

Posted on 2011-03-09
8
652 Views
Last Modified: 2012-05-11
Hi Guys, I have an Excel Macro that works on my Excel 2007 but not my colleagues Excel 2007.
He gets the error message "Run time error 1004 Paste Special Method of Range Class failed
on the line "rtarget Paste Special xlValues" Any ideas why? See below code.


Sub Macro8()
'
Dim i As Integer
Dim rtarget As Range


Dim Daypath As String

Daypath = Worksheets("Macros").Range("Daypath").Value
Daypath = Format(Daypath, "DD.MM.YY")
 
    Workbooks.Open Filename:= _
        "G:\MFL 2011\Cash Products\System Checks & Recs\All Trading Report\12. Mar 11\" & Daypath & " - All Trading.xlsm" _
        , Notify:=False
   
    Sheets("All Trading").Select
    'ActiveSheet.ShowAllData
    Selection.AutoFilter Field:=12, Criteria1:=">5", Operator:=xlOr, _
        Criteria2:="<-5"
    ActiveSheet.Range("$A$1:$X$156000").AutoFilter Field:=4, Criteria1:=Array( _
        "13047", "13049", "13029", "FIRT", "13036", "16004", "HYFRN", "13095", "FIHB", "FINB", "FIMC", "FIRD", "FIRM", "FISC", "TRSY", "FIEMG"), Operator:=xlFilterValues
   
    Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.SpecialCells(xlCellTypeVisible).Select
    Selection.Copy
    Windows("5.Outright MTM Mar Check - Oracle.xlsm").Activate
 
    Set rtarget = Sheets("Trading p&l").Range("A1").End(xlDown).Offset(1)
   
 rtarget.PasteSpecial xlPasteValues
 
0
Comment
Question by:JCutcliffe
  • 4
  • 3
8 Comments
 
LVL 33

Expert Comment

by:jppinto
ID: 35081429
Set rtarget = Sheets("Trading p&l").Range("A1").End(xlDown).Offset(1)
rtarget.PasteSpecial xlPasteValues

You don't have a Select statment to select the place where you want to PasteSpecial your values...maybe that's the problem. Try something like this to see if it works:

Set rtarget = Sheets("Trading p&l").Range("A1").End(xlDown).Offset(1)
rtarget.Select
rtarget.PasteSpecial xlPasteValues

jppinto
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 35081554
There should be no need to select. Try replacing this:

Selection.Copy
    Windows("5.Outright MTM Mar Check - Oracle.xlsm").Activate
  
    Set rtarget = Sheets("Trading p&l").Range("A1").End(xlDown).Offset(1)
    
 rtarget.PasteSpecial xlPasteValues

Open in new window


with:
Selection.Copy
Workbooks("5.Outright MTM Mar Check - Oracle.xlsm").Sheets("Trading p&l").Range("A1").End(xlDown).Offset(1).PasteSpecial xlPasteValues

Open in new window

0
 

Author Comment

by:JCutcliffe
ID: 35081675
Why does it work on my 2007 Excel computer but not my Colleagues?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 85

Expert Comment

by:Rory Archibald
ID: 35081718
Don't know specifically - perhaps he has some other code running that clears the clipboard when your code switches workbooks.
0
 

Author Comment

by:JCutcliffe
ID: 35082493
How do I investigate that? Bizarely, his computer also deletes Named Ranges in Excel whenever
he opens a specific spreadsheet. Any idea why?
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 35083812
Try opening Excel in Safe Mode (hold down Ctrl while opening normally) then see if the same behaviour occurs.
0
 

Author Comment

by:JCutcliffe
ID: 35096624
For some reason too, Named Ranges keep disappearing in my colleagues Excel 2007 spreadsheet
when he runs the same spreadsheet. Any idea why this would happen?
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 35096767
Does he have his copy of Office fully patched up to date? I have heard of disappearing named ranges before but I thought that had been fixed.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ejb wildfly example 2 16
Excel formula with two ifs 9 25
Need Help with Mapping and Toggling 3 20
Turn date into age 17 31
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question