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

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
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
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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
Back
Top