Macros to delete row based on matching values in two columns to user defined values

andre14_7

New Member
Joined
Dec 1, 2015
Messages
1
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!
 
Last edited:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Forum statistics

Threads
1,215,761
Messages
6,126,735
Members
449,333
Latest member
Adiadidas

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