Delete Row Based On Multiple Factors

Nanogirl21

Active Member
Joined
Nov 19, 2013
Messages
330
Office Version
  1. 365
Platform
  1. Windows
Hi, can someone please help me with a macro. I am trying to delete a row if it does not contain:


1 in column M and 3 in column N
OR
1 in column O and 3 in column P
OR
1 in column Q and 3 in column R
OR
1 in column S and 3 in column T
OR
1 in column U and 3 in column V
OR
1 in column W and 3 in column R


The range of data is from A7:AF:500.


Thank you.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
So, are you saying that if ANY of those 6 conditions are met, it should NOT be deleted, otherwise delete it?

Also, do you have a typo in your last condition?
1 in column W and 3 in column R
If it was consistent with the others, it would be:
1 in column W and 3 in column X
 
Last edited:
Upvote 0
If my assumptions are correct, this VBA code should do what you want:
Code:
Sub MyDeleteRows()


    Dim myRow As Long
    Dim myCount As Long
    Dim myCond As Long
    
    Application.ScreenUpdating = False
    
'   Loop through all rows backwards
    For myRow = 20 To 7 Step -1
'       Reset counter
        myCount = 0
'       Loop through 6 conditions and add one to counter if condition is met
        For myCond = 1 To 6
            If Cells(myRow, (myCond * 2) + 11) = 1 And Cells(myRow, (myCond * 2) + 12) = 3 Then
                myCount = myCount + 1
            End If
        Next myCond
'       If no conditions are met, delete the row
        If myCount = 0 Then Rows(myRow).Delete
    Next myRow
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,272
Members
449,075
Latest member
staticfluids

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