Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm getting totaly crazy with this error: Runtime error 1004 - The Paste-Special method of this object can't be executed

This is my code:
VB
If TypeName(cb) Like "CheckBox" Then
                    If cb.Value = True Then
                        Worksheets(ReiternameAttribute).Cells(header - 1,3).Copy
                        Selection.Offset(0, 1).Select
                        With Selection
                            .Borders.LineStyle = xlContinuous
                            .Value = cb.Caption
                            .PasteSpecial Paste:=xlFormats
                        End With
                    End If
End If


if i go through the code with F8, I get the error in the line .PasteSpecial.
But when I switch to the excel-sheet, the right cell is selected. I also tried this and got the same error:
VB
Range("A1:A2").Copy
Range("A31:A32").PasteSpecial
Posted

1 solution

Based on your code I'd say that the selection is lost when you set the borders. Because of that there's nothing to paste when you hit the PasteSpecial call.

Instead of
VB
With Selection
    .Borders.LineStyle = xlContinuous
    .Value = cb.Caption
    .PasteSpecial Paste:=xlFormats
End With

try what happens with
VB
With Selection
    .PasteSpecial Paste:=xlFormats
    .Borders.LineStyle = xlContinuous
    .Value = cb.Caption
End With
 
Share this answer
 
Comments
Chi Ller 23-Jul-15 5:15am    
it works :D thank you (:
Wendelius 23-Jul-15 5:45am    
You're welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900