Error in vba line

A

ADK

Using Excel 2000:

I get a runtime error '1004' PasteSpecial method of Range class failed

Selection.PasteSpecial Paste:=xlDataValidation, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False

Here is code:

Sub addrow()

Dim CellOne As Range

Set CellOne = ActiveCell

If CellOne.Value = 1 Then

MsgBox "You can not insert a row above Number 1", 64, "Invalid"

Exit Sub

End If
Range("A" & ActiveCell.Row).Select
ActiveCell.EntireRow.Insert
ActiveCell.Offset(-1, 0).Select
Cells(ActiveCell.Row + 1, ActiveCell.Column).Select
Selection.FillDown
ActiveCell.Offset(-1, 2).Select
Selection.Copy
ActiveCell.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlDataValidation, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False

End Sub
 
S

Sandy

Selection.PasteSpecial Paste:=xlPasteValidation, Operation:=xlNone,
SkipBlanks:=False, Transpose:=False
 
S

Sandy

Here is complete rework of you code. It isn't giving me any errors when
I run it, and since I don't know what you're trying to do with it I
can't tell if it's doing what you want it to do. Anyways, make sure
that if you are copying and pasting this directly form the post that
you are careful about how the code is placed into your editor.
Sometimes the code if it's too long for the post it will wrap it and
finish the string on the next line which will give you an error unless
you use " _". If you have any other questions send me an email.

Sub addrow()
Dim CellOne As Range
Set CellOne = ActiveCell
If CellOne.Value = 1 Then
MsgBox "You can not insert a row above Number 1", 64, "Invalid"
Exit Sub
End If
Range("A" & ActiveCell.Row).Select
ActiveCell.EntireRow.Insert
ActiveCell.Offset(-1, 0).Select
Cells(ActiveCell.Row + 1, ActiveCell.Column).Select
Selection.FillDown
ActiveCell.Offset(-1, 2).Select
Selection.Copy
ActiveCell.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValidation, _ 'continue on
next line
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End Sub

Good luck
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top