Copy and paste to another sheet

JannetteChristie

Board Regular
Joined
Dec 14, 2015
Messages
119
I have a button on a sheet with the following code, but am getting the following error message:

Sub CopyDPSSP()

Dim InputRow
Worksheets("DPS-SP").Range("W2:BC2").Copy
InputRow = Application.InputBox(Prompt:="Which Input sheet row should this be copied to ? ", Type:=1)


On Error GoTo 0
If InputRow > 0 Then
Worksheets("Input Sheet").Range("E" & InputRow).PasteSpecial Paste:=xlPasteValues
Else
MsgBox "No row selected"
End If

End Sub

Error message is Run-time error '1004': PasteSpecial method of Range class failed

Can anyone help please?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
A few questions, do you
1) have sheet protection on the Input sheet?
2) have merged cells on either sheet?
3) use text to columns?
 
Upvote 0
I was playing around with it, and it didn't like it when I had the InputBox AFTER the Copy command had been activated. Moving it around, it worked when I did this:
Code:
Sub CopyDPSSP()

Dim InputRow As Long
InputRow = Application.InputBox(Prompt:="Which Input sheet row should this be copied to ? ", Type:=1)

On Error GoTo 0
If InputRow > 0 Then
    Sheets("DPS-SP").Range("W2:BC2").Copy
    Sheets("Input Sheet").Range("E" & InputRow).PasteSpecial Paste:=xlPasteValues
Else
    MsgBox "No row selected"
End If

End Sub
 
Upvote 0
Perfect, thanks very much.
However after running the script, in the Input Sheet I cannot select just one cell - when I move between cells more than 1 is highlighted.
 
Upvote 0
I don't seem to have that problem. It works fine for me.
However, you can try adding the following line to make sure that you are out of copy mode:
Code:
Sub CopyDPSSP()

Dim InputRow As Long
InputRow = Application.InputBox(Prompt:="Which Input sheet row should this be copied to ? ", Type:=1)

On Error GoTo 0
If InputRow > 0 Then
    Sheets("DPS-SP").Range("W2:BC2").Copy
    Sheets("Input Sheet").Range("E" & InputRow).PasteSpecial Paste:=xlPasteValues
[COLOR=#ff0000]    Application.CutCopyMode = False[/COLOR]
Else
    MsgBox "No row selected"
End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,334
Members
449,077
Latest member
Jocksteriom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top