VBA code for deleting row from a table works only sometimes.

  • I have the following code which deletes a row from a table ("EPAtable"). It deletes the row which contains the value selected in the "EPAlist" listbox which is on a userform.



    This code works only sometimes. Sometimes when I run the macro, nothing happens, I get an error or excel crashes.


    I am just learning VBA, so perhaps there is a better way to accomplish what it is I am trying to accomplish?

  • Re: VBA code for deleting row from a table works only sometimes.


    Try the attached example. Click on the button to show the UserForm then click on an item in the ListBox to delete the corresponding row in the table and update the EPAList.


    Code in the UserForm is:


    Note that the ListBox is loaded with individual items rather than using the RowSource Property, better practice to do it that way. You will need to change the Sheet name to your actual sheet name for the sheet that has the "EPAtable" Table. Also, change Column1 (in 3 paces) to suit the actual header of the first column of the "EPAtable" Table.

    Files

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.