I want the ability to add a row anywhere in a table besides the first row (row 18) . The code I have to dynamical add a row is below. I already built in restrictions that only allow the user to add a row into a designated table. I just don't want them to add a new row to the absolute first row of data in the table (it is not the header of the table) Any ideas?
Code:
Sub Checkbook_AddRow()
'Declare local variables------
Dim lo As ListObject
Dim ws As Worksheet
Dim wsSettings As Worksheet
Dim Rng As Range
'-----------------------------
'Set worksheet, list object, and range variables--------------
Set wsSettings = ThisWorkbook.Worksheets("Settings")
Set ws = ActiveSheet
Set lo = ws.ListObjects(1)
Set Rng = Selection
'Verify that cells are within table body range
'---------------------------------
If InRange(Rng, lo.DataBodyRange) Then
DoEvents
Else
MsgBox "Selected Range is not within the table. Please select the row where you would like to add information.", vbInformation, "Range not detected"
End
End If
'---------------------------------
ws.Unprotect wsSettings.Range("Settings_Password")
' only this section is new
ws.Rows(IIf(ActiveCell.Row > topLine, _
ActiveCell.Row, _
topLine)) _
.EntireRow.Insert
ws.Protect wsSettings.Range("Settings_Password"), AllowFiltering:=True
End Sub