Arnab Mitra
Arnab Mitra

Reputation: 21

Delete rows from table based on listbox selection

I have lstPrev as an ActiveX Listbox. It has 10 rows of data. Once the user selects a row (single select) and presses the delete button, it should delete the corresponding row in dbTable.

Sub DelRows()

     Dim i As Integer

     Set i = ActiveSheet.lstPrev.ListIndex + 1 'to ensure column headers are not deleted

     dbTable.ListRows(i).Delete

End Sub

Upvotes: 1

Views: 465

Answers (1)

horst
horst

Reputation: 713

First, you don't Set an integer value. Set is for Objects like Ranges. To assign a value to an Integer variable, just do i =

Second, to refer to your Table, use ListObjects

This will work:

Sub DelRows()

     Dim i As Integer

     i = ActiveSheet.lstPrev.ListIndex + 1 'to ensure column headers are not deleted

     ListObjects("dbTable").ListRows(i).Delete

End Sub

Upvotes: 2

Related Questions