+ Reply to Thread
Results 1 to 9 of 9

delete selected row from user form

Hybrid View

  1. #1
    Registered User
    Join Date
    04-01-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    delete selected row from user form

    i have a problem while deleting the row in excel sheet from User Form.
    when i search a data using search text box, it displayed in List Box1,but a problem arise if there are multiple search results(userform eg:smith).
    then it is deleted only the first found, and not the result selected in listbox

    So Please can any one do the correct code for me.

    Waiting for reply,

    qwzx
    Attached Files Attached Files
    Last edited by qwzx; 04-06-2011 at 07:13 AM.

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

    Re: delete selected row from user form

    It deletes the selected row for me
    Hope that helps.

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

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    04-01-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: delete selected row from user form

    eg:when i search smith two results are found
    if you want to delete the second result from the listbox is delete the first result

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

    Re: delete selected row from user form

    basically you need to find the row associated with the record when you click on the record in the listbox. So some sort of entry reference number for each record would help

  5. #5
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: delete selected row from user form

    Hi qwzx
    The cell reference was set up in

    http://www.excelforum.com/excel-prog...ace-buton.html
    so in the delet code
    r = ListBox1.Column(6)
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  6. #6
    Registered User
    Join Date
    04-01-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: delete selected row from user form

    hi pike
    I tried your recommendation but will not work

  7. #7
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: delete selected row from user form

    what did you try?

  8. #8
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: delete selected row from user form

    Hi qwzx
    You will have to change the dimention of r to a long and then

    Private Sub cmddel_Click()
    Dim r As Long
    Dim msgResponse As String    'confirm delete
      
        Application.ScreenUpdating = False
        'get user confirmation
        
        msgResponse = MsgBox("THIS WILL DELETE THE SELECTED ROW, CONTINUE", _
                             vbCritical + vbYesNo, "DELETE ENTRY")
        Select Case msgResponse    'action dependent on response
        Case vbYes
            'c has been selected by Find button
           r = ListBox1.Column(6)' add r value here
            Rows(r).EntireRow.Delete    'add this bit remove entry by deleting row
            'restore form settings
            With Me
                .cmdrep.Enabled = False     'prevent accidental use
                .cmddel.Enabled = False    'prevent accidental use
                .cmdsub.Enabled = True        'restore use
                'clear form
                .txtfn.Value = vbNullString
                .txtln.Value = vbNullString
                .txtloc.Value = vbNullString
                .txtph.Value = vbNullString
                .txteml.Value = vbNullString
                .cbostat.Value = vbNullString
            End With
        Case vbNo
            Exit Sub    'cancelled
        End Select
        Application.ScreenUpdating = True
    End Sub
    column six of the list box is used to store the data lines row number

  9. #9
    Registered User
    Join Date
    04-01-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: delete selected row from user form

    Thanks Pike,it works

+ 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