Hi everyone,
So I have this userform for data entry (image below). The problem started when I add the "Delete selected row" button.
When I tried adding and deleting a rows, it works fine the first few times, but then, the error message (2nd image) popped up around the 5th or 6th addition. Do you know what may have gone wrong? Thanks so much for your time.
Here is my codes to add a row:
Here is my codes to delete a row:
So I have this userform for data entry (image below). The problem started when I add the "Delete selected row" button.
When I tried adding and deleting a rows, it works fine the first few times, but then, the error message (2nd image) popped up around the 5th or 6th addition. Do you know what may have gone wrong? Thanks so much for your time.
Here is my codes to add a row:
VBA Code:
Sub AddIng()
Dim ListBoxRow
Dim IngLstTB As ListObject
Set IngLstTB = IngListBox.ListObjects(1)
'Add ingredients to ingredient list box
IngLstTB.ListRows.Add '<------ Here is where the debugger pointed to
ListBoxRow = IngLstTB.ListRows.Count
IngLstTB.DataBodyRange.Cells(ListBoxRow, 1) = Meal_form.Ingredients.Value
IngLstTB.DataBodyRange.Cells(ListBoxRow, 2) = Meal_form.Weight.Value
'show the list of entered data in the listbox
Meal_form.Controls("lstIngredient").RowSource = "Ingredient_listbox!" & IngListBox.ListObjects(1).DataBodyRange.Address
'reset fields
Meal_form.Controls("Ingredients").Value = ""
Meal_form.Controls("Weight").Value = ""
End Sub
Here is my codes to delete a row:
VBA Code:
Private Sub cmdDeleteIng_Click()
Dim IngRow As Long
Dim ListBoxRow As Integer
ListBoxRow = lstIngredient.ListIndex + 1
IngListBox.ListObjects(1).ListRows(ListBoxRow).Delete
End Sub