I need to write a simple macro to copy the last row in a spreadsheet and paste it as a new row in the other sheet.
Please help.
Thanx in advance.
I need to write a simple macro to copy the last row in a spreadsheet and paste it as a new row in the other sheet.
Please help.
Thanx in advance.
Last edited by VBA Noob; 03-19-2009 at 05:42 PM.
Please take a few minutes to read the Forum Rules about thread titles, and then edit yours to make it descriptive of your problem.
Entia non sunt multiplicanda sine necessitate
Thank you. Try this:
![]()
Sub x() Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).EntireRow.Copy _ Destination:=Worksheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1) End Sub
Thanx for responding.
This code does copy from sheet 1 to sheet 2.
But i want to copy the last row as in the latest row from sheet1 and paste it in the sheet 2 as a new row.
Can i call LASTINROW function.
if so how can i incorporate it in the code.
I am new to writing macros.... so need help.
Last edited by swe1; 03-19-2009 at 03:36 PM.
The code copies the row containing the last used cell in Sheet1 column A to the row below the last used cell in Sheet2 column A. If you need something different, please explain clearly.But i want to copy the last row as in the latest row from sheet1 and paste it in the sheet 2 as a new row.
Pardon?Can i call LASTINROW function.
Hi,
Thanks SHG!
Your code works but with an error 1004.
I tried the following code.It seems to be working but still have problems while pasting the row.
Note:I tried working between the sheets in the same workbook.
Please help.Any help would be appreciated.
Thanks!
Here is my code.
![]()
Sub FindLastCell() Dim LastCell As Range Dim EmptyCell As Range With ActiveSheet Sheets("Sheet1").Select Set LastCell = .Cells(.Rows.Count, "B").End(xlUp) If IsEmpty(LastCell) Then Rows(LastCell).Select Application.CutCopyMode = False Selection.Copy End If 'Rows("262:262").Select 'Application.CutCopyMode = False 'Selection.Copy 'Sheets("Sheet2").Select 'Rows("26:26").Select 'ActiveSheet.Paste Sheets("Sheet2").Select Set EmptyCell = .Cells(.Rows.Count, "B").End(xlUp) 'If IsEmpty(EmptyCell) Then 'Do nothing 'Else Set EmptyCell = EmptyCell.Offset(1, 0) Rows(EmptyCell).Select 'Range(Range("B" & EmptyCell), Range("IV" & EmptyCell.Row).End(xlToLeft)).Select ActiveSheet.Paste ' End If End With End Sub
Last edited by swe1; 03-21-2009 at 08:53 PM.
Please edit your post to add code tags.
Hi Shg,
I did add code Tags.
I don't see what the problem is. Please post a workbook and explain in context.
Hello Shg,
I have attached my workbook.
I get the runtime error 1004
at the following code
Rows(Emptycell.select)
Replace all of your code with this:
![]()
Sub CopyLastRow() Worksheets("Sheet1").Cells(Rows.Count, "B").End(xlUp).EntireRow.Copy _ Destination:=Worksheets("Sheet2").Cells(Rows.Count, "B").End(xlUp).Offset(1, -1) End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks