PDA

View Full Version : Insert multiple rows-Delete Rows with formulas



klutz
07-14-2009, 08:27 AM
Public Sub AddDeleteRow()
Dim mpSelect As String
Dim mpRow As Range

mpSelect = InputBox("Choose to add (A) or delete (D) a row")
If mpSelect = "" Then Exit Sub
If UCase(mpSelect) = "D" Then

On Error Resume Next
Set mpRow = Application.InputBox("Use the mouse to select any cell in the row you will delete", Type:=8)
On Error Goto 0
If Not mpRow Is Nothing Then

ActiveSheet.Unprotect Password:="password"
mpRow.EntireRow.Delete
End If
Else

On Error Resume Next
Set mpRow = Application.InputBox("Use the mouse to select any cell in the row you will add after", Type:=8)
On Error Goto 0
If Not mpRow Is Nothing Then

ActiveSheet.Unprotect Password:="password"
mpRow.Offset(1, 0).EntireRow.Insert
Cells(mpRow.Row, "N").Resize(, 3).Copy Cells(mpRow.Row + 1, "N")
End If
End If

ActiveSheet.Protect Password:="password"
End Sub

I opened this other post becuase the previous one was posted as solve I was not quite sure of how to revert it.:dunno

Hey guys, the macro works great.

One other question, when I select to delete I am able to delete multiple rows but when I add i'm only able to add one row at a time withe the formulas copied into the new row. I can select various rows to add but only the first row added has the formula and not the rest.

How can the macro be changed to allow multiple row inserts while copying the formulas into them as well? I am currently inserting rows form a continuos location, I am not selecting multiple different locations (example: row 25-30, and not row 25, 40, or 50)

Great, apreciate all the help that has been given..I love this site. :hi:

Bob Phillips
07-14-2009, 08:46 AM
I answered in the original thread klutz.