+ Reply to Thread
Results 1 to 5 of 5

Userform - Delete Button VBA

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Userform - Delete Button VBA

    Hi. I was working with mehmetcik on this same userform and have another question, so I opened a new thread.

    The original thread is here:
    https://www.excelforum.com/excel-pro...ml#post5294014

    The sample form attached is the one we were working on. I want to use the Global Variable "Entry" that was created to modify the code for the Delete button on the ContactSearch userform.

    Currently column A is populated with the address of the first column of the table and that is used to know which table row to delete when the button is pushed.

    Private Sub CmdDeleteContact_Click()
    
    'Deletes the row of selected contact.
    Dim X
        On Error GoTo booboo
        X = Split(ListContactSearch.Column(5), "'!")
        Application.GoTo Sheets(X(0)).Range(X(1)), True
        Selection.ListObject.ListRows(3).Delete
        Unload Me
        Range("B1").Select
        
        Exit Sub
    
    booboo:           MsgBox "Oops! Please click on a contact in the list, then click Open Contact."
    Is want to get rid of the information in column A completely and remove the last column in the named range "ContactSearchResults" and use the "Entry" variable to determine what row to delete when the button is pressed.

    Any help is appreciated.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Userform - Delete Button VBA

    
    Private Sub CmdDeleteContact_Click()
    
    'Deletes the row of selected contact.
    
    If Entry > 8 Then
        Range("C" & Entry & ":BQ" & Entry).Value = ""
        
    Else
    
    MsgBox "Oops! Please click on a contact in the list, then click Open Contact."
    
    End If
    
    End Sub
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: Userform - Delete Button VBA

    Thank you again, mehmetcik.

    The error message listed in the code displays when I press the "Delete" button.

    Also, is it possible to delete the Table Row instead of putting in "" for the value?

    I don't want to leave a blank row in the table.

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Userform - Delete Button VBA

    I don't see why.

    
    Private Sub CmdDeleteContact_Click()
    
    'Deletes the row of selected contact.
    If Entry > 8 Then
    
        Range("C" & Entry).EntireRow.Delete
        
    Else
    
    booboo:           MsgBox "Oops! Please click on a contact in the list, then click Open Contact."
    
    End If
    
    End Sub

  5. #5
    Forum Contributor
    Join Date
    11-08-2017
    Location
    Murfreesboro, TN
    MS-Off Ver
    MS 365
    Posts
    168

    Re: Userform - Delete Button VBA

    That works perfectly! I had another spreadsheet open that was apparently causing confusion. Once I closed that spreadsheet I didn't get the error. In other words...user error!

    Thank you so much for your help!

+ 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. Delete command button from UserForm Frame
    By nicksyplonk in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-09-2020, 04:05 PM
  2. Userform button to delete record
    By Mahmoudelnemr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-06-2019, 02:27 PM
  3. [SOLVED] Userform: Code for DELETE on a command button
    By Gal403 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-25-2014, 01:28 AM
  4. [SOLVED] UserForm : Want to link Listbox1 with Listbox2 and delete data with one button
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-01-2014, 11:18 AM
  5. How to delete the last row on the selected sheet from userform button?
    By Shacker in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-12-2013, 09:04 AM
  6. Delete Button On UserForm
    By markrennolds in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 04-08-2010, 11:56 AM

Tags for this Thread

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