ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   I want to create a "Insert Row" button to insert a new row at the. (https://www.excelbanter.com/excel-programming/325499-i-want-create-insert-row-button-insert-new-row.html)

Georges

I want to create a "Insert Row" button to insert a new row at the.
 
I want to create a "Insert new row" button to insert new rows at the bottom
of my table that contains the same functions as previous rows...

Rowan[_2_]

I want to create a "Insert Row" button to insert a new row at the.
 
Assuming your data starts in Cell A1, your button could run the code:

Sub NewRow()

Application.ScreenUpdating = False

Dim lastRow As Long
Dim lastCol As Long
Dim startrng As Range

Set startrng = ActiveCell

lastRow = Cells(Rows.Count, "A").End(xlUp).Row
lastCol = Cells("1", Columns.Count).End(xlToLeft).Column

Range(Cells(lastRow, 1), Cells(lastRow, lastCol)).Copy
Range(Cells(lastRow + 1, 1), Cells(lastRow + 1, lastCol)) _
.PasteSpecial Paste:=xlPasteFormulas
Range(Cells(lastRow + 1, 1), Cells(lastRow + 1, lastCol)) _
.PasteSpecial Paste:=xlPasteFormats

On Error Resume Next
Range(Cells(lastRow + 1, 1), Cells(lastRow + 1, lastCol)) _
.SpecialCells(xlCellTypeConstants).ClearContents

Application.Goto startrng

Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub

Regards
Rowan

"Georges" wrote:

I want to create a "Insert new row" button to insert new rows at the bottom
of my table that contains the same functions as previous rows...



All times are GMT +1. The time now is 03:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com