Im using the following code to delete usernames from a sheet, and consequently from a dynamic range. The code worked fine but Im trying to add some code that checks to make sure the username entered in the combo box Username is present in the dynamic range Usernames. If it is not present then it displays a message informing the user that the username does not exist.
I am currently getting runtime error 13 Type mismatch on the third line: If Username.Value = Rng Then
Private Sub CommandButton4_Click()
Set Rng = Worksheets("Users").Range("Usernames")
If Username.Value = Rng Then
Msg = "Are you sure you want to delete the username: " & Username.Value & "?"
Ans = MsgBox(Msg, vbQuestion + vbYesNo)
Select Case Ans
Case vbYes
Dim c As Range
With Me.Username.Value
Set c = Worksheets("Users").Range("Usernames").Find(Me.Username.Value, , xlValues, xlWhole, xlByRows, xlNext, True, False, False)
If Not c Is Nothing Then
c.EntireRow.Delete
Me.Username.Value = Sheets("Users").Range("G1").Value
With Worksheets("Users")
Username.List() = .Range("Usernames").Value
End With
End If
End With
Exit Sub
Case vbNo
Exit Sub
End Select
Else
MsgBox "Username does not exits. Please selet a user to delete from the Username dropdown list."
End If
End Sub
Thanks,
James
Bookmarks