VBA code not pasting data correctly, keeps overwriting data in target sheet

handoverhammer

New Member
Joined
Mar 30, 2018
Messages
24
Hi Excel Wizards,

The function of this code is to copy data from one sheet to another using a drop down and message box, also adding a timestamp. Unfortunately the destination is targeting row 2, not the last blank row, and overwriting any data in row 2 of the destination sheet when the copy is triggered in the drop down.

FYI: drop down is in "H", the rows being copied are A:I, time stamp is in "F"

Here's what I have right now:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)If Not Intersect(Target, Range("H:H")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Dim Lastrow As Long
Dim ans As String
ans = Target.Value
Dim Response As VbMsgBoxResult
If ans = "Initial" Then
Response = MsgBox("Move to Sandbox?", vbQuestion + vbYesNo)
End If
If Response = vbNo Then Exit Sub
If ans = "Initial" Then
Lastrow = Sheets("Sandbox").Cells(Rows.Count, "I").End(xlUp).Row + 1
Cells(Target.Row, "F").Value = Now
Rows((Target.Row)).Copy Destination:=Sheets("Sandbox").Rows(Lastrow): Rows(Target.Row).Delete
Sheets("Sandbox").Select
End If
'

Please advise.

Thank you!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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