Macro to delete certain rows not containing one of 3 values

chriscarr

New Member
Joined
Aug 22, 2010
Messages
29
Hi guys

I was wondering if there is a macro which will delete a row if a cell in a certain column doesn;t contain one of three values. For example the criteria is in coloum L and the row needs to be left on the sheet if it contains 20000, 40000 or 60000.

I've seen macros to delete rows if it doesn't contain one value but is it possible to base it on 3?

Thanks in advance for your help.

Chris
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
maybe something like this
Code:
Sub rowsdelete()
Dim lr As Long, e, i As Long
lr = Range("L:L")(Rows.Count).End(3).Row
For i = lr To 1 Step -1
    e = Range("L:L")(i).Value
    If (e <> 20000) * (e <> 40000) * (e <> 60000) Then Rows(i).EntireRow.Delete
Next i
End Sub
 
Upvote 0
Perhaps

Code:
Sub DelRows()
Dim LR As Long, i As Long
LR = Range("L" & Rows.Count).End(xlUp).Row
For i = 2 To LR
    If IsError(Application.Match(Range("A" & i).Value, Array(20000, 40000, 60000))) Then Rows(i).Delete
End If
End Sub
 
Upvote 0
er... Peter
Rich (BB code):
Sub DelRows()
Dim LR As Long, i As Long
LR = Range("L" & Rows.Count).End(xlUp).Row
For i = 2 To LR
    If IsError(Application.Match(Range("A" & i).Value, Array(20000, 40000, 60000))) Then Rows(i).Delete
End If
End Sub
etc.
 
Upvote 0
er... Peter
Rich (BB code):
Sub DelRows()
Dim LR As Long, i As Long
LR = Range("L" & Rows.Count).End(xlUp).Row
For i = 2 To LR
    If IsError(Application.Match(Range("A" & i).Value, Array(20000, 40000, 60000))) Then Rows(i).Delete
End If
End Sub
etc.

Ooh, Err :oops:

Rich (BB code):
Sub DelRows()
Dim LR As Long, i As Long
LR = Range("L" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
    If IsError(Application.Match(Range("L" & i).Value, Array(20000, 40000, 60000))) Then Rows(i).Delete
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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