Results 1 to 4 of 4

Thread: How to delete cells' values through a multiselect listbox?

  1. #1
    Member
    Join Date
    Jul 2013
    Posts
    40
    Rep Power
    0

    How to delete cells' values through a multiselect listbox?

    Hi to all,

    I have the following issue. Say for example that I have in Sheet1 the following A1: title and A2:A11 a named range called test_range

    I have made Userform1 that contains Listbox1 and command button Delete
    I have used .RowSource to populate the items of the listbox and I have also set the listbox to be multiselect.

    I want to select one or more items in the listbox and upon pressing delete I want the respective cells in the named range to have a zero value.

    I have the following code but it deletes only the first of the selected items and not all of them.

    Any help would be handy... thanks in advance


    Code:
    Private Sub Delete_Click()
        Dim strRange As String
         With ListBox1
             strRange = .RowSource
               For I = 0 To .ListCount - 1
                 If .Selected(I) = True Then
                     Range(strRange).Cells(I + 1, 1).Value = 0
                 End If
               Next
             .RowSource = vbNullString
             .RowSource = strRange
         End With
    End Sub
    Keep in mind all vba I know has been googled...

  2. #2
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    13
    Why don't you change the values in the listbox of the items you want to be deleted to 0 ?

  3. #3
    Member
    Join Date
    Jul 2013
    Posts
    40
    Rep Power
    0
    Quote Originally Posted by snb View Post
    Why don't you change the values in the listbox of the items you want to be deleted to 0 ?
    What exactly do you suggest? Could you give me an example?
    Keep in mind all vba I know has been googled...

  4. #4
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    13
    See the attachment.
    Show the userform by clicking the button 'start'
    To set an item in the listbox to '0': doubleclick it.
    Attached Files Attached Files

Similar Threads

  1. Replies: 15
    Last Post: 01-07-2014, 12:42 AM
  2. Replies: 3
    Last Post: 09-06-2013, 01:13 PM
  3. DELETE PAST FORMULA IN EMPTY CELLS
    By Zayn_21 in forum Excel Help
    Replies: 1
    Last Post: 08-15-2013, 05:39 PM
  4. Delete Entire Row For All Empty Cells In Column
    By johnreid7477 in forum Excel Help
    Replies: 4
    Last Post: 06-15-2013, 05:50 AM
  5. Replies: 13
    Last Post: 06-10-2013, 09:05 AM

Posting Permissions

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