+ Reply to Thread
Results 1 to 8 of 8

Deleting cells from a specific row, specified by a combo box

  1. #1
    Registered User
    Join Date
    10-04-2009
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    77

    Deleting cells from a specific row, specified by a combo box

    Hi All

    I've got a list of users within a sheet. The sheet is split vertically in two. So the users are in column L with password, nickname etc through to column P. They start from row 6. So the first user is in cell L6.

    A combo box (selectuser) shows all the users from cell L6 to the last user on sheet "Setup". This works fine.

    I've got my combo box linked to other text fields so when you select a user, it displays their nickname in the nickname field etc.

    I have a delete button on my userform, which, when clicked, deletes the user.

    If I use the following formula, it clears the cells from the row selected based on the selection in the combo box. However when you then load up the userform again, it loads all users fine on selecting from the combo box until you click on a user that was below the one you just removed. It also leaves those cells blank rather than just deleting them.

    Please Login or Register  to view this content.
    So I need to work out how to delete the cells and shift the ones below up a row, based on the combo box selection.

    I tried this:

    Please Login or Register  to view this content.
    However I get an error saying that there are too many arguments for the range. So I need to figure out how to select cells L,M,N,O,P for the selected row based on the combo box, delete them, and shift the cells below up.

    Does anyone know how I can do this?

    Thanks
    Last edited by Smurlos; 01-17-2011 at 06:43 AM.

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

    Re: Deleting cells from a specific row, specified by a combo box

    Please Login or Register  to view this content.



  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Deleting cells from a specific row, specified by a combo box

    Hello Smurlos,

    The comma in a Range is used to demark the start of the range and the end of the range. You get the error because there is more than one comma. You can use multiple commas only if they are inside quotation marks.

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    10-04-2009
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    77

    Re: Deleting cells from a specific row, specified by a combo box

    Quote Originally Posted by Leith Ross View Post
    Hello Smurlos,

    The comma in a Range is used to demark the start of the range and the end of the range. You get the error because there is more than one comma. You can use multiple commas only if they are inside quotation marks.

    Please Login or Register  to view this content.

    Hi Leith, I tried this but I get "run time error 1004 - select method of range class failed" :-(

    Thanks
    Carl

  5. #5
    Registered User
    Join Date
    10-04-2009
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    77

    Re: Deleting cells from a specific row, specified by a combo box

    Hi guys, sorry I've sorted it! The macro before was selecting a different sheet, so the wrong sheet was selected! I've made it select the right sheet first and then execute the deletion of the cells and it works fine :-)

    Thanks for your help Leith.

    Regards
    Carl

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Deleting cells from a specific row, specified by a combo box

    Hello Carl,

    The error tells me that the variable RowToDel is not a valid row number. Since you are adding 6 to the ListIndex property, you will never see a value less than 5. I don't see what is causing the error.

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

    Re: Deleting cells from a specific row, specified by a combo box

    If you only want to clear certain cells in a row use Excel's builtin facilities:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-04-2009
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    77

    Re: Deleting cells from a specific row, specified by a combo box

    Quote Originally Posted by Leith Ross View Post
    Hello Carl,

    The error tells me that the variable RowToDel is not a valid row number. Since you are adding 6 to the ListIndex property, you will never see a value less than 5. I don't see what is causing the error.
    It's all sorted now. The macro that I'd run previous to that was selecting the "Bookings" sheet, and those cells in question were part of a merged cell on that sheet I believe. The sheet I needed selected was "Setup" so I just inserted

    Please Login or Register  to view this content.
    Before and it now works perfectly, thanks.

    Quote Originally Posted by snb View Post
    If you only want to clear certain cells in a row use Excel's builtin facilities:

    Please Login or Register  to view this content.
    Hi snb, I didn't want to just 'clear contents' i needed the actual rows removed as it was affecting the list range - when I selected another user after deletion, it was taking data from the wrong rows. This is however all sorted now - thank you anyway.

    Regards
    Carl

+ 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