Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2011

    Unanswered: Userform Listbox data problem

    I have a spreadsheet with a 'userform' which has a 'listbox' which displays the data found in a worksheet (which is populated by a user via various sheets), all that is fine however I am trying to set it up so that when a user identifies a row in the userform they can select the row and then select "delete" (using a command button) and it will then delete that row of data from the worksheet.

    I have some code I got from an old workbook but can't get it to work proparly.

    I have attached a copy of the worksheet and userform if someone can help.
    Attached Files Attached Files

  2. #2
    Join Date
    May 2012
    In the Inialization change the rowsource to

    aList = Range("CF1:CK" & NextRow)
    Me.ListBox1.List = aList
    Then in the Commandbutton2
    Private Sub CommandButton2_Click()
    Dim Response As String
    Dim strDelName As String
    With Me.ListBox1
        If .ListIndex > 0 Then
        strDelName = .List(.ListIndex, 2) & " " & .List(.ListIndex, 3)
        Response = MsgBox("You have selected " & strDelName & " for Deletion." _
        & vbNewLine & vbNewLine & " If this is correct please select ""Yes""" _
        & "and the record will be deleted.", vbYesNo + vbInformation, _
        "Delete Record Information")
            If Response = vbYes Then
                .RemoveItem .ListIndex
                Worksheets("Summary").Rows(.ListIndex + 1).Delete xlShiftUp
                MsgBox strDelName & " has been deleted.", vbOKOnly + vbInformation, _
                    "Delete Record Information"
               MsgBox "You have chosen not to delete " & strDelName & " from the system." _
                , vbOKOnly + vbInformation, "Delete Record Information"
            End If
        End If
    End With
    Exit Sub
        MsgBox Prompt:=Err.Number & " " & Err.Description, _
               Buttons:=vbInformation + vbOKOnly, _
        Resume ExitProc
    End Sub

Posting Permissions

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