+ Reply to Thread
Results 1 to 16 of 16

Delete record from listbox via Userform

  1. #1
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Delete record from listbox via Userform

    Hello all,

    The code below is a part of Roy Cox's code for data entry from a userform linked to a Listbox. The part below is for deleting a record by deleting the entire row.
    I however rather have the code to delete only the cells, rather than the whole row.
    Is this possible?


    Please Login or Register  to view this content.

  2. #2
    VoG™
    Guest

    Re: Delete record from listbox via Userform

    Try

    Please Login or Register  to view this content.

  3. #3
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Delete record from listbox via Userform

    Maybe

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Re: Delete record from listbox via Userform

    No luck!
    The corresponding cells are on a different sheet.
    perhaps I am doing something wrong.

    btw, the cell right to it should also be deleted

    Please Login or Register  to view this content.

  5. #5
    VoG™
    Guest

    Re: Delete record from listbox via Userform

    Maybe

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Re: Delete record from listbox via Userform

    That, as a replacement of the code I gave in my last post, results in a runtime error 91

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Delete record from listbox via Userform

    @VoG™

    Looking at the code, this may throw an error
    Please Login or Register  to view this content.
    Perhaps this will not
    Please Login or Register  to view this content.
    Maybe that the "1" is inferred...think not but don't know...haven't tested.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  8. #8
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Re: Delete record from listbox via Userform

    Hello VoG,
    The error persists. "Object variable or With block variable not set"

  9. #9
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Re: Delete record from listbox via Userform

    The error disappears when addidng the following code to it.
    Please Login or Register  to view this content.
    Although it gives a short flickering, nothing happens?

  10. #10
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Delete record from listbox via Userform

    Just use

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Re: Delete record from listbox via Userform

    Quote Originally Posted by Bob Phillips View Post
    Just use

    Please Login or Register  to view this content.
    The cells are on a different sheet.

  12. #12
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Delete record from listbox via Userform

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    [B]Doing this will ensure you get the result you need![/B
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  13. #13
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Re: Delete record from listbox via Userform

    Enclosed a dummy workbook.

    its about "Private Sub cmbDelete_Click()"
    When the commandbutton "Delete" is hit i like it to remove the corresponding cells of the selected record from the listbox.

    some functions became unusable while reducing it to this dummy workbook, so please don't mind them.
    Attached Files Attached Files

  14. #14
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Delete record from listbox via Userform

    Be clever: do not adapt the worksheet while using teh userform.
    You can delete every item in the listbox.
    When clicking the 'continue/close' button you can adapt the worksheet according to the items that listbox1 contains.

    the only thing you have to do is:

    Please Login or Register  to view this content.



  15. #15
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Re: Delete record from listbox via Userform

    I can't get it working.
    It gives no error but nothing happens.
    This is how I put it in the code

    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    08-19-2009
    Location
    Netherlands, Amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    585

    Re: Delete record from listbox via Userform

    I also tried this:
    But again without positive result.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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