Delete if criteria met

Hank2

New Member
Joined
Aug 9, 2006
Messages
26
I have four columns. If column D contains the numeral 1, I want a macro that will either retain it or delete it based on the following criteria

For example, say D1 contains a 1. Then the macro should look at offset C1 to see if it is the same name as in offset B1. If so move on.

If not, then the macro should note the value in A1. Say that value is 3.

If any names in column B that have a value of 3 in column A, match the name in C1 which also has a value of 3 (in this case) then the “1” in D1 should be deleted.

Then go down the list which contains 200 names.

Thanks
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
try this on a copy of your file.
VBA Code:
Sub do_delete()
Application.ScreenUpdating = False

For r = 2 To Range("A" & Rows.Count).End(xlUp).Row

If Cells(r, "D") <> 1 Then GoTo 99
If Cells(r, "B") = Cells(r, "C") Then GoTo 99
If Cells(r, "B") = Cells(r, "A") Or Cells(r, "C") = Cells(r, "A") Then Cells(r, "D").ClearContents

99 Next r

Application.ScreenUpdating = True
End Sub
 
Upvote 0

rpaulson

Thanks for your effort,but it did not work. I don't know why cause looking at it with debug it makes sense. But I did get it solved with another macro method. Thank you very much.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

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