I've used this board extensively for the past three months as I've learned VBA for a project I'm working on. This is my first post because I can't seem to find a workable solution, hopefully the Excel gurus here can help...
I need a VBA code to delete a single row of data when the value in column "E" matches user defined entry A in a user form AND the value in column "Q" matches the user defined entry B on the same user form.
I have a working code for one criteria (below), but can't seem to make it work for two...
Private Sub DeleteButton_Click()
Dim lReply As Long
Dim ws As Worksheet
Dim strSearch As String
Dim aCell As Range
Set ws = Sheets("AuditData")
lReply = MsgBox("Are you sure you want to delete this audit?", vbCritical + vbYesNo)
If lReply = vbNo Then
Exit Sub
End If
Sheet9.Unprotect Password:="xxxxx"
With ws
AppSearch = DeleteAppInput.Value
Set aCell = .Columns(5).Find(What:=AppSearch, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not aCell Is Nothing Then
.Rows(aCell.Row).Delete
MsgBox "The audit record was deleted"
Else
MsgBox "An audit for that application was not found"
End If
End With
Sheet9.Protect Password:="xxxxx"
Unload Me
End Sub
Thanks for your help!
I need a VBA code to delete a single row of data when the value in column "E" matches user defined entry A in a user form AND the value in column "Q" matches the user defined entry B on the same user form.
I have a working code for one criteria (below), but can't seem to make it work for two...
Private Sub DeleteButton_Click()
Dim lReply As Long
Dim ws As Worksheet
Dim strSearch As String
Dim aCell As Range
Set ws = Sheets("AuditData")
lReply = MsgBox("Are you sure you want to delete this audit?", vbCritical + vbYesNo)
If lReply = vbNo Then
Exit Sub
End If
Sheet9.Unprotect Password:="xxxxx"
With ws
AppSearch = DeleteAppInput.Value
Set aCell = .Columns(5).Find(What:=AppSearch, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not aCell Is Nothing Then
.Rows(aCell.Row).Delete
MsgBox "The audit record was deleted"
Else
MsgBox "An audit for that application was not found"
End If
End With
Sheet9.Protect Password:="xxxxx"
Unload Me
End Sub
Thanks for your help!
Last edited: