Forum Discussion
joshbernabe
Jul 31, 2024Copper Contributor
Macro overwrites first row instead of pasting the data on the next row.
I'm trying to get this macro to paste data into the next row but all it does is overwrite the the first row. Can anyone help me please? Sub ValidateExportData() ' ' ValidateExportData Macro ' ...
joshbernabe
Aug 01, 2024Copper Contributor
Thanks for your response. I have manage to fixed this issue by doing it like this:
DataSource.Range("E11").Copy
DataDestination.Range("D" & DataDestination.Range("D" & DataDestination.Rows.Count).End(xlUp).Row + 1).PasteSpecial xlPasteValues
DataSource.Range("E12").Copy
DataDestination.Range("E" & DataDestination.Range("E" & DataDestination.Rows.Count).End(xlUp).Row + 1).PasteSpecial xlPasteValues
I now have another issue, the data keeps getting pasted on row 893 and onwards instead of starting on row 2. Any idea what might be causing this?
This is my new code for more context:
Option Explicit
Sub ValidateExportData()
'
' ValidateExportData Macro
'
' Keyboard Shortcut: n/a
'
Dim RequestForm As Workbook
Dim TaskCalendar As Workbook
Dim DataSource As Worksheet
Dim DataDestination As Worksheet
Dim FindEmptyRow As Long
Set RequestForm = ThisWorkbook
Set TaskCalendar = Workbooks.Open("S:\RANDD\PILOT_PLANT\Evangeline\Josh\Task Management Calendar System\Task Calendar.xlsx")
Set DataSource = RequestForm.Worksheets("Analysis Request Form")
Set DataDestination = TaskCalendar.Worksheets("2025")
DataSource.Range("E11").Copy
DataDestination.Range("D" & DataDestination.Range("D" & DataDestination.Rows.Count).End(xlUp).Row + 1).PasteSpecial xlPasteValues
DataSource.Range("E12").Copy
DataDestination.Range("E" & DataDestination.Range("E" & DataDestination.Rows.Count).End(xlUp).Row + 1).PasteSpecial xlPasteValues
TaskCalendar.Save
End Sub
Aug 01, 2024
joshbernabe I'm not sure why that's happening, but you can use your keyboard to simulate what Excel does with the End(xlUp) action, and that may help determine the cause. Just select a cell in column D on that sheet, and press Ctrl+DownArrow until your selection goes all the way to the bottom of the sheet. Then press Ctrl+UpArrow and see what cell it takes you to.
You can also add something like this to your macro temporarily to help debug it:
MsgBox DataDestination.Range("D" & DataDestination.Rows.Count).End(xlUp).Address