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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to Insert a row in Excel

Status
Not open for further replies.

grisold

Technical User
Mar 2, 2007
2
CA
I'm trying to create an ActiveX control button to insert a row at the bottom of my Excel spreadsheet. The thing is though, I want it so that regardless of which cell you're on, it will add a line to the bottom of the list. Therefore, the first time the button is clicked, it might Insert at row 15 and the next time row 16 and so on. I've got this code to start with,

Rows("15:15").Select
Selection.Insert Shift:=xlDown

but need it to move down one row each time it's used. Please advise. Thanks!
 


Hi,

If the row you want to insert is at the BOTTOM of your table, why insert at all?

Just reference the next unused row...
Code:
dim lNextRow as long

lNextRow = objSheet.Cells(objSheet.Cells.Rows.Count, "A").End(xlUp) + 1


Skip,

[glasses] [red][/red]
[tongue]
 
I want to use the Insert function so that my formulas and formatting (including a drop-down menu) are carried down.
 
You may try this:
ActiveSheet.Cells(ActiveSheet.Cells.Rows.Count, "A").End(xlUp).EntireRow.Insert Shift:=xlDown

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top