Can somebody help a bit please, I have cobbled together the below code to allow the user to insert extra rows. But I have a couple of problems.
1. I need be able to force the user to select the entire row, because at the moment if they select a cell not the row, the code just inserts a copy the active cell. I did try “ActiveCell.EntireRow.Copy” but this errored out on the next line “Selection.Insert Shift:=xlDown”.
2. The other part I would like to achieve is I would like to put something in column O like (do not insert rows here) so the code would check for this value and prevent any rows being entered, with a msgbox stating that you cannot insert rows here. This will enable me to protect parts of the sheet from the user inserting rows.
Any help is much appreciated
1. I need be able to force the user to select the entire row, because at the moment if they select a cell not the row, the code just inserts a copy the active cell. I did try “ActiveCell.EntireRow.Copy” but this errored out on the next line “Selection.Insert Shift:=xlDown”.
2. The other part I would like to achieve is I would like to put something in column O like (do not insert rows here) so the code would check for this value and prevent any rows being entered, with a msgbox stating that you cannot insert rows here. This will enable me to protect parts of the sheet from the user inserting rows.
Any help is much appreciated
Code:
Sub AddRows()
Dim n As Integer
Dim Ans As Variant
' On Error Resume Next
ActiveSheet.Unprotect
Ans = MsgBox("Have you selected the entire row where you want to add the extra rows", vbYesNo)
If Ans = vbYes Then
n = InputBox("How many rows do you require?")
If n >= 1 Then
For numtimes = 1 To n
Selection.Copy
Selection.Insert Shift:=xlDown
Next
End If
ActiveSheet.Protect
Else
ActiveSheet.Protect
Exit Sub
End If
End Sub