Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Macros..Insert row at end of list?

Status
Not open for further replies.

DJKAOS

Technical User
Jun 30, 2000
101
US
How can I make a macro that will insert a new row at the end of my data? I am able to do it manually, but I want to automate it and add it to a button (the button part I can do I just dont know how to select the last row of my data)

Thanks
 
I f you have contiguous data (that is, without any breaks in the data) than all you need to do is go to Data, Form and click New. I believe you are limted 30 columns in your form. (not sure about that)
 
This will work...

Sub_GoLastRow
Application.Goto Reference:="datatop"
LastCell = [A65536].End(xlUp).Offset(1, 0).Address
Range(LastCell).Select
End Sub

The first row references a cell named "datatop" - an arbitrary name - you can use whatever name you prefer. The reason for using a range name, is so that your routine will work regardless of which worksheet it is activated from. The name "datatop" is of course assigned to a cell somewhere at the top of your data, but it can be anywhere on the sheet containing your data. If you already have a name assigned (like "data") then used that name instead.

Method of Assigning a Range Name:
a) Highlight the cell or range-of-cells
b) Hold down the <Control> key and hit <F3>
c) Type the name
d) Hit <Enter>

I hope this helps. :) Please advise as to how you make out.

Regards, ...Dale Watson dwatson@bsi.gov.mb.ca
 
Thanks, I just tried that..doesn't work the way I want though.

 
Thanks, that way seemed to almost work
Application.Goto Reference:=&quot;ID&quot;
LastCell = [A65536].End(xlUp).Offset(1, 0).Address
Range(LastCell).Select

The problem is that I have my data, then some formulas..then a table below that, and the code you gave me seems to jump all the way down past everything..I want it to just go to the end of my data, or the end of my data+1.

Thanks for any more help
 
This should work...

Sub Go_NextRow()
Application.Goto Reference:=&quot;ID&quot;
LastRow = ActiveCell.End(xlDown).Offset(1, 0).Address
Range(LastRow).Select
End Sub

This assumes the cell named &quot;ID&quot; is in the first column of your data, and that there are NO blank cells in this column.

Please advise as to how you make out.

Regards, ...Dale Watson dwatson@bsi.gov.mb.ca
 
That Works Perfect, thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top