Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Find Next Empty Row and Paste Data

I am trying to find a way to setup a macro to find the next empty row and paste data from one workbook to another workbook.
[123 byte] By [scgamecock] at [2007-11-11 11:58:02]
# 1 Re: Find Next Empty Row and Paste Data
Within the same spreadsheet or a workbook in a different spreadsheet?
Hack at 2007-11-11 17:20:51 >
# 2 Re: Find Next Empty Row and Paste Data
A workbook in a different spreadsheet.

I have this code that I have been playing with, but I am not sure if I am on the right track or not.

FinalRow = Worksheets("sheet1").Range("A65536").End(xlUp).Row
' Find the last row of data
' Loop through each row
For x = 1 To FinalRow
' Decide if to copy based on column A
ThisValue = Range("A" & x).Value
' could be any value
If ThisValue = "yes" Then
Worksheets("sheet2").Range("A" & x & ":L" & x).Copy
NextRow = Worksheets("sheet1").Range("A65536").End(xlUp).Row + 1
Worksheets("sheet1").Range("A" & NextRow).PasteSpecial = xlValues
End If
Next x
scgamecock at 2007-11-11 17:21:51 >
# 3 Re: Find Next Empty Row and Paste Data
Well, when you run the code do you get the desired results?

If no, what happens?
Hack at 2007-11-11 17:22:50 >
# 4 Re: Find Next Empty Row and Paste Data
I do not get the desire results. When I run the code, It appears that Column A insterts the correct data, but the other columns seem to duplicate the same data that is already on the worksheet.
scgamecock at 2007-11-11 17:23:51 >
# 5 Re: Find Next Empty Row and Paste Data
Would it make it easier if they were in the same workbook? If so, that will be fine.
scgamecock at 2007-11-11 17:25:00 >