I'm using Excel 07, windows XP. The range is A4:M5 right now; however, will grow over time.
I have found this code while browsing the msg. board and added some of my own. What I'm trying to accomplish is to allow a user to press a command button to insert a new row(s). This macro would copy the data in the last row of the worksheet, including formulas, then paste the formulas in the next row(s) down and clear the row(s) (leaving the formulas) for data entry. I would also like for the cursor to end up in the first active row inserted and in the cell in column F.
It is not working correctly yet...
I have found this code while browsing the msg. board and added some of my own. What I'm trying to accomplish is to allow a user to press a command button to insert a new row(s). This macro would copy the data in the last row of the worksheet, including formulas, then paste the formulas in the next row(s) down and clear the row(s) (leaving the formulas) for data entry. I would also like for the cursor to end up in the first active row inserted and in the cell in column F.
It is not working correctly yet...
Code:
Sub InsertNewRows()
ActiveSheet.Unprotect Password:="aaa"
Dim RowCnt As Integer
RowCnt = Application.InputBox _
(prompt:="How many rows do you want to insert" & _
" starting with row " & ActiveCell.Row & "?", Type:=1)
If RowCnt = 0 Then End
Rows(ActiveCell.Row & ":" & ActiveCell.Row + RowCnt - 1).Insert _
Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Rows(ActiveCell.Row - 1).Copy
Rows(ActiveCell.Row & ":" & ActiveCell.Row + RowCnt - 1). _
PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Rows(ActiveCell.Row).Select
Selection.ClearContents
ActiveSheet.Protect Password:="aaa", DrawingObjects:=True, _
Contents:=True, Scenarios:=True
End Sub