Solved

Error 1004 paste special - Excel VBA

Posted on 2011-09-09
8
738 Views
Last Modified: 2012-05-12
Hi,

When I add "Selection.ClearContents" in the code, I have an error message (1004 paste special) on :
  Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False.

Without that code "Selection.ClearContents", it's working.

How to clear the cell contents?

Thanks
'Copy
    Sheets("Corriger les donnees").Select
    Columns("D:k").Select
    Selection.Copy
    
    'Paste
    Sheets("Exporter les donnees").Select
    Sheets("Exporter les donnees").Activate
    Sheets("Exporter les donnees").Columns("A:h").Select
    Selection.ClearContents '??????
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
  
    Application.CutCopyMode = False

Open in new window

0
Comment
Question by:Karl001
  • 3
  • 2
  • 2
8 Comments
 
LVL 24

Accepted Solution

by:
StephenJR earned 250 total points
ID: 36510037
I think the CC interrupts the copy/paste. Try this:
With Sheets("Exporter les donnees").Columns("A:h")
    .ClearContents
    Sheets("Corriger les donnees").Columns("D:k").Copy
    .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
End With

Open in new window

0
 
LVL 92

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 250 total points
ID: 36510042
ClearContents emptied the copy buffer.  Try:

    With Worksheets("Exporter les donnees")
        .Range("A:h").ClearContents
        Worksheets("Corriger les donnees").Range("D:k").Copy
        .Range("A:h").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
    End With
  
    Application.CutCopyMode = False

Open in new window

0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 36510045
Wow, Stephen and I were thinking pretty much the exact same thing :)
0
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.

 

Author Comment

by:Karl001
ID: 36510091
Soory  I gave the point at the wrong solution. ( 8:36)

How can I correct that
0
 

Author Comment

by:Karl001
ID: 36510210
Not the wrong solution, but the first one
How can correct the situation
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 36510213
Indeed Patrick, except emptying the copy buffer is much better!

You can request attention. I think the fairest thing would be to split the points 50-50.
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 36510921
Karl001,

I'd be happy with a split as well.

If you click the Request Attention link, you can ask the Mods to reopen the question.

Patrick
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

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