Command button to delete row based on combo box selection.

draccus

New Member
Joined
Nov 30, 2016
Messages
5
Hi

I'm trying to achieve the above on a user form with the below code and keep getting a key type error! can any one please help!?!

Code:
Sub remove_key_click()  
Dim kName As String


kName = cbo_KN.Value


If Worksheets("Keys").Range("KeyName").Value = kName Then
        ans = MsgBox("Delete " & kName & " from list?", vbYesNo)
            If ans = vbYes Then
                Worksheets("Keys").Range("KeyName").EntireRow.Delete
            End If
             End If
             
        MsgBox "The Key has been deleted!"
    
End Sub


Private Sub UserForm_Initialize()


cbo_KN.List = Worksheets("Keys").Range("KeyName").Value
cbo_KID.List = Worksheets("Keys").Range("KeyID").Value
cbo_KCAT.List = Worksheets("Keys").Range("KeyCatergory").Value


cbo_CNM.List = Worksheets("Contacts").Range("Contacts").Value
cbo_CID.List = Worksheets("Contacts").Range("ContactID").Value
cbo_CDPT.List = Worksheets("Contacts").Range("ContactDept").Value
cbo_CEML.List = Worksheets("Contacts").Range("ContactEmail").Value


cbo_UNM.List = Worksheets("users").Range("users").Value


End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

draccus

New Member
Joined
Nov 30, 2016
Messages
5
For anyone like me who is new to this and needs an answer that code was PANTS!

I did a bit more googling and found a different code, which when applied with my own relevant range/combo boxes names etc has worked perfectly!!

See below!

Code:
Sub remove_key_click()

  ans = MsgBox("Delete key from list?", vbYesNo)
    If ans = vbYes Then


Dim RowCount As Long
Dim Found As Range


RowCount = Worksheets("Keys").Range("KeyName").CurrentRegion.Rows.Count
Set Found = Worksheets("Keys").Columns("A").Find(what:=Me.cbo_KN.Value, LookIn:=xlValues, lookat:=xlWhole)
Found.EntireRow.Delete (xlShiftUp)


        MsgBox "The Key has been deleted!"
        
If ans = vbNo Then MsgBox "Key not deleted"
    
Lendingadmin.cbo_KN.Value = ""
Lendingadmin.cbo_KID.Value = ""
Lendingadmin.cbo_KCAT.Value = ""


End If
    
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,133,529
Messages
5,659,343
Members
418,498
Latest member
nattynat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top