Add a Row dynamically anywhere in a table besides the first row

Src016

New Member
Joined
May 21, 2019
Messages
10
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
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Maybe...

Code:
' only this section is newws.Rows(IIf(ActiveCell.Row > topLine, _
        ActiveCell.Row, _
        topLine + 1)) _
        .EntireRow.Insert

???
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top