+ Reply to Thread
Results 1 to 5 of 5

Code for submit button to delete row dependant on combobox value

Hybrid View

  1. #1
    Registered User
    Join Date
    03-22-2013
    Location
    West Sussex
    MS-Off Ver
    Office 365
    Posts
    84

    Code for submit button to delete row dependant on combobox value

    Hi there have uploaded this spreadsheet a few times now. I am on my final question now.

    I have created userform3 and started to program it however some suggestions on finishing it please!

    I want an item to be selected in combobox1. Click delete item and a warning 'Are you sure you want to delete item'. Cancel = close form or yes to search for the row in sheet 1 and sheet 2 and delete the entire row.

    Look forward to your help.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    03-22-2013
    Location
    West Sussex
    MS-Off Ver
    Office 365
    Posts
    84

    Re: Code for submit button to delete row dependant on combobox value

    Any ideas anyone?

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Code for submit button to delete row dependant on combobox value

    Hi mezza89

    Try this
    Private Sub CommandButton1_Click()
      Dim lrow As Long, lReply As Long
    
      lrow = Range("PRODUCTS").Find(Me.ComboBox1.Value).Row
    
      lReply = MsgBox(Prompt:="Are you sure you want to delete item " & Me.ComboBox1.Value, _
                      Buttons:=vbYesNoCancel, Title:="Delete Item")
    
      If lReply = vbCancel Then
        Exit Sub
      ElseIf lReply = vbNo Then
        Exit Sub
      End If
    
      With Sheet1.Columns(1)
        .Rows(lrow).EntireRow.Delete
      End With
    
      With Sheet2
        lrow = .Columns("A").Find(what:=Me.ComboBox1.Value, LookIn:=xlValues, lookat:=xlWhole).Row
        .Rows(lrow).EntireRow.Delete
      End With
    
      ComboBox1.Value = ""
    
      Unload Me
    
    End Sub
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  4. #4
    Registered User
    Join Date
    03-22-2013
    Location
    West Sussex
    MS-Off Ver
    Office 365
    Posts
    84

    Re: Code for submit button to delete row dependant on combobox value

    Hi thanks for your help works perfectly how ever is it possible you can help with one more bit of code?

    At the moment if the product is not in sheet2 it comes up with debugger obviously because the object is not there. Can we tweak the code so that it will ignore sheet 2 if the product is not there?

    Thanks in advance :-)

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Code for submit button to delete row dependant on combobox value

    Hi mezza89

    Try this
    Private Sub CommandButton1_Click()
      Dim lrow As Long, lReply As Long
    
      lrow = Range("PRODUCTS").Find(Me.ComboBox1.Value).Row
    
      lReply = MsgBox(Prompt:="Are you sure you want to delete item " & Me.ComboBox1.Value, _
                      Buttons:=vbYesNoCancel, Title:="Delete Item")
    
      If lReply = vbCancel Then
        Exit Sub
      ElseIf lReply = vbNo Then
        Exit Sub
      End If
    
      With Sheet1.Columns(1)
        .Rows(lrow).EntireRow.Delete
      End With
    
      With Sheet2
        On Error GoTo SkipMe
        lrow = .Columns("A").Find(what:=Me.ComboBox1.Value, LookIn:=xlValues, lookat:=xlWhole).Row
        .Rows(lrow).EntireRow.Delete
      End With
    
    SkipMe:
      ComboBox1.Value = ""
      Unload Me
    End Sub

+ 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. Macro delete submit button when item selected from drop dowm list
    By vnoelte in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-05-2014, 12:33 PM
  2. [SOLVED] Enforcing submit button in userform with combobox?
    By excellenthelp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-17-2013, 01:41 PM
  3. Replies: 1
    Last Post: 02-05-2012, 09:31 PM
  4. Code to reset combobox dependant on another combobox
    By j.farr3ll in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-08-2011, 08:21 AM
  5. Create a Submit button save filename as A1, submit email unc path, etc.
    By briant97 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-30-2009, 09:52 AM

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