+ Reply to Thread
Results 1 to 13 of 13

Adding delete code on userform to delete a row on sheet by selecting item on a listbox

  1. #1
    Registered User
    Join Date
    07-30-2017
    Location
    texas
    MS-Off Ver
    2016
    Posts
    99

    Adding delete code on userform to delete a row on sheet by selecting item on a listbox

    I am trying to add a delete command button code to this userform that will perform as follows: when an item is selected on the listbox, a user can click on the DELETE command button, a message box will pop up to confirm item deletion. Upon selecting "Yes", the appropriate row on sheet1 (MovieDatabase) will be deleted and the listbox refreshed. i have attached an example for reference.

    I appreciate any help anyone can offer.

    david
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    9,214

    Re: Adding delete code on userform to delete a row on sheet by selecting item on a listbox

    How about
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    07-30-2017
    Location
    texas
    MS-Off Ver
    2016
    Posts
    99

    Re: Adding delete code on userform to delete a row on sheet by selecting item on a listbox

    thanks for the response!

    i applied the code and when i click on the delete command button, the message box does appear, no errors appear, however the selected entry that was chosen on the listbox did not delete the row on sheet1. any suggestions?

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    9,214

    Re: Adding delete code on userform to delete a row on sheet by selecting item on a listbox

    Is that in your test file? as it works for me.

  5. #5
    Registered User
    Join Date
    07-30-2017
    Location
    texas
    MS-Off Ver
    2016
    Posts
    99

    Re: Adding delete code on userform to delete a row on sheet by selecting item on a listbox

    it does work for the entries that are in the test file, however, i did notice that when i entered a new entry using the userform and then went about deleting it, the entry was not deleted for some reason. Interesting... Do you get the same outcome?

  6. #6
    Registered User
    Join Date
    07-30-2017
    Location
    texas
    MS-Off Ver
    2016
    Posts
    99

    Re: Adding delete code on userform to delete a row on sheet by selecting item on a listbox

    this anomaly seems to only occur when the search field of the userform is used to find a movie. only then when the item is selected in the listbox does this anomaly occur. this does not just affect newly entered items.

  7. #7
    Forum Expert
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    2,001

    Re: Adding delete code on userform to delete a row on sheet by selecting item on a listbox

    Just paste the code below into the delete button.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    07-30-2017
    Location
    texas
    MS-Off Ver
    2016
    Posts
    99

    Re: Adding delete code on userform to delete a row on sheet by selecting item on a listbox

    this works except for the anomaly listed previously. in other words, if i use the search textbox on the userform to find a certain entry and then select that entry on the listbox and then try to delete it, it will not delete that entry. you have to remove the entry by manually finding it in the listbox, then once it is selected it can be removed by your code. any suggestions on why this is happening and if there is a fix?

    thanks in advance for your suggestions!

  9. #9
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    9,214

    Re: Adding delete code on userform to delete a row on sheet by selecting item on a listbox

    How about
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    07-30-2017
    Location
    texas
    MS-Off Ver
    2016
    Posts
    99

    Re: Adding delete code on userform to delete a row on sheet by selecting item on a listbox

    Perfect... now i will spend the next hour figuring out how you did that You are a genius! This problem is solved! Thanks so much for your patience and advice.

  11. #11
    Forum Expert
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    2,001

    Re: Adding delete code on userform to delete a row on sheet by selecting item on a listbox

    That is because as you type in the textbox your listbox filters out rows that do not match, in doing so the entire listindex changes.
    To use the contents of the filtered listbox will involve a complex search routine - does the frequency demand such complexity - just use the full listbox for simplicity.
    torachan.

  12. #12
    Registered User
    Join Date
    07-30-2017
    Location
    texas
    MS-Off Ver
    2016
    Posts
    99

    Re: Adding delete code on userform to delete a row on sheet by selecting item on a listbox

    it seems that Fluff13 code works without any problems. i do, however, appreciate all your assistance! I did add reputation for you. Again "Thank You"

  13. #13
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    9,214

    Re: Adding delete code on userform to delete a row on sheet by selecting item on a listbox

    Glad to help & thanks for the feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Delete selected item from ListBox with KeyDown event
    By esbencito in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-08-2020, 03:57 AM
  2. Filtered ListBox Selected item delete in sheet Entire Row
    By sijostephen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-05-2019, 05:38 PM
  3. [SOLVED] Listbox selecting another first item after modification on sheet trough userform
    By dark_prince69 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-24-2018, 06:09 PM
  4. Code to delete entire row on sheet when selected in listbox
    By chrismccarthy17 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-02-2016, 12:18 AM
  5. [SOLVED] delete listbox item and off sheet
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-11-2014, 05:53 AM
  6. Delete an item from listbox
    By questionguy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-19-2013, 12:27 PM
  7. [SOLVED] Delete a Item from a Listbox.
    By abhay_547 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-20-2010, 11:56 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1