Inserting Copied Data into different Worksheet with VBA and Command Button

StuReaRitchie1982

New Member
Joined
Dec 19, 2016
Messages
1
Apologies if the answer to this is somewhere within the forum already - I've searched high and low, copying bits and bats from here and there and still the error I get keeps appearing.

I am trying to finalise my code for inserting copied data into a user selected row but within a different worksheet.

Forgive me if the code seems all over the place, I am learning from scratch and as I say, am copying from other codes and deciphering it and using trial and error. I have succeeded so far and to be fair the whole code below works fine when inserting the copied data onto the same sheet as the original data and command button, but just shows a run-time 1004 error (Insert Method of Range class failed) when running the below macro via another button with the same macro applied, but on the destination sheet.

Sub PasteRow()


Dim sh As Worksheet
Set sh = ActiveSheet
'select the A column of the chosen row (if the used chooses a cell in row C or D for instance)
ActiveSheet.Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 1)).Select
With ActiveSheet
'insert the copied data into the selected row (user selected)
Selection.EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove <------- Error Appears on this line all the time

'Below code reapplies the protection to the workbook which works fine
Dim myPassword As String
myPassword = ""
For Each sh In ActiveWorkbook.Worksheets
sh.Protect Password:=myPassword
Next sh
End With
End Sub

As I say the code works fine when running within one sheet over and over but I need the data to be able to be inserted into another sheet, of which there a numerous different destination sheets and rows which the user could choose!

Any help would be great.

Thanks!
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,191,178
Messages
5,985,142
Members
439,942
Latest member
bkexcel11230

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
Top