easy question - select and copy last row in spreadsheet

Shyyde

New Member
Joined
Apr 9, 2002
Messages
3
I have a pretty easy and quick question. I'm trying to write a macro that copies the last row in a spreadsheet, and then pastes the last row. This will be used for an "Add New Record" button that I am assigning the macro to. the idea is that if the last row is always a "blank row" that has the formulas, then as long as the user hits the "Add New Record" button, the formulas will be in the row for the New Record.

Here's what I have now:

Sub test()
'
' test Macro
' Macro recorded 4/10/2002 by Ryan M. Cavaliere
'

'
Sheets("Env Site Assessments").Select
ActiveCell.SpecialCells(xlLastCell).Select
Rows("49:49").Select
Application.CutCopyMode = False
Selection.Copy
Selection.Insert Shift:=xlDown
End Sub


The problem is that Row 49 is being copied, not the last row. I just need to know the correct syntax to select the last row. I thought it was xlLastRow, but that doesn't seem to work.

If someone could take a minute to answer this email, it would be greatly appreciated.

Thanks!

Ryan Cavaliere
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try the following code:

[a1].End(xlDown).EntireRow.Select

It will select the last row as long as column A contains the extent of your data.
 
Upvote 0
Al,

Thank you much for your prompt answer.

I have a spreadsheet with columns A through V. The code that you posted comes close to what I want, but it doesn't quite work. I want to copy a "blank" row at the bottom, only the row is not really blank - it contains formulas. Using the code that you posted, I am copying the last row that has information in column A. Actually, I want to copy a row below that - a row that only has the formaulas in the cells, but that's it.

What is the syntax to select the last row, and then to copy and insert the copied row, thereby moving the last row down one row?

I want to use this so that the user just hits an "Add New Record" button.



On 2002-04-10 06:54, Al Chara wrote:
Try the following code:

[a1].End(xlDown).EntireRow.Select

It will select the last row as long as column A contains the extent of your data.
 
Upvote 0
Copy latest row in file A and paste into latest row in file B

Dear Sir

I have been try to write a VBA code in the macro to copy the latest row in file A and wanna to paste them in file B latest row.

can pls kindly advise what is the suitable code which i can use to execute the above mention function?


Merry Christmas & Happy new year! :)
Many THanks!


Jim
 
Upvote 0

Forum statistics

Threads
1,214,863
Messages
6,121,978
Members
449,058
Latest member
oculus

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