+ Reply to Thread
Results 1 to 9 of 9

Code to delete entire row on sheet when selected in listbox

  1. #1
    Registered User
    Join Date
    01-29-2014
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    42

    Code to delete entire row on sheet when selected in listbox

    I have a userform that displays data from a sheet, in my code I want to delete the enitre row that is selected in the listbox. I found code from another site but it didn't work code is below. what am i doing wrong?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Code to delete entire row on sheet when selected in listbox

    What exactly is going wrong?

    Errors? The wrong row being deleted?

    Also, are you initially populating the listbox using the ListFillRange property?

    If you are have you tried using List instead?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    01-29-2014
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    42

    Re: Code to delete entire row on sheet when selected in listbox

    Quote Originally Posted by Norie View Post
    What exactly is going wrong?

    Errors? The wrong row being deleted?

    Also, are you initially populating the listbox using the ListFillRange property?

    If you are have you tried using List instead?
    I am getting the error code "application defined or object defined error".

    Everything else in the code works except for the row doesn't delete.

    The listbox is populated by rowsourse. I just want to be able to click on a row in the list box and have the command button delete that row on the worksheet

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Code to delete entire row on sheet when selected in listbox

    If you use RowSource/ListFillRange when populating a listbox/combobox you will have problems deleting from the range you are using as the source.

    Instead of using RowSource/ListFillRange you can use List and you should have no problems deleting.

    Not sure what the source range is but this is how you would use List and this code would go in the form's Initialize event.
    Please Login or Register  to view this content.
    PS You might want to add a sheet reference to the above to make sure the listbox is populated from the correct worksheet.

  5. #5
    Registered User
    Join Date
    01-29-2014
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    42

    Re: Code to delete entire row on sheet when selected in listbox

    Quote Originally Posted by Norie View Post
    If you use RowSource/ListFillRange when populating a listbox/combobox you will have problems deleting from the range you are using as the source.

    Instead of using RowSource/ListFillRange you can use List and you should have no problems deleting.

    Not sure what the source range is but this is how you would use List and this code would go in the form's Initialize event.
    Please Login or Register  to view this content.
    PS You might want to add a sheet reference to the above to make sure the listbox is populated from the correct worksheet.
    Thanks, will give it a go. Can you give n example of the code needed to delete row row data on the sheet that is selected in the listbox as the code I currently have doesn't state 'selected' which leads me to believe I may have the wrong code

  6. #6
    Registered User
    Join Date
    01-29-2014
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    42

    Re: Code to delete entire row on sheet when selected in listbox

    Bump.........

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Code to delete entire row on sheet when selected in listbox

    Not sure what you mean by 'selected', are you working with a multiselect listbox?

    Also not too sure what range/sheet you are populating the listbox from so can't really post specific code for deleting a row.

  8. #8
    Registered User
    Join Date
    01-29-2014
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    42

    Re: Code to delete entire row on sheet when selected in listbox

    Quote Originally Posted by Norie View Post
    Not sure what you mean by 'selected', are you working with a multiselect listbox?

    Also not too sure what range/sheet you are populating the listbox from so can't really post specific code for deleting a row.
    By selected I mean when clicked on. When you click on the row in the postbox it is highlighted. The list is is populated by sheet "mattbrowndata" cells U1003:AD2002

    Thanks man

  9. #9
    Registered User
    Join Date
    01-29-2014
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    42

    Re: Code to delete entire row on sheet when selected in listbox

    And no it's only a single select listbox with 10 columns

+ 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. VBA to delete rowsource of selected row in listbox
    By chrismccarthy17 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-01-2016, 02:24 PM
  2. [SOLVED] delete rows of selected items on listbox
    By 9599lorenzo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-30-2015, 01:57 PM
  3. Loop backwards through selected range - delete entire row from selected cells
    By scottbass in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-20-2014, 09:21 AM
  4. [SOLVED] "Delete Selected" in Search Result listbox deletes first row, instead of selected row.
    By Faustus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-06-2013, 02:11 AM
  5. [SOLVED] Modify code to only work on a selected area and not the entire sheet
    By Harribone in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-23-2013, 03:07 PM
  6. [SOLVED] Trying to copy selected items from sheet to listbox then selected back to sheet
    By BigWes1960 in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 03-14-2013, 03:27 PM
  7. VBA delete entire row from rowsource with listbox
    By Hilton1982 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-19-2012, 01:02 AM

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