Delete row on cell value RANGE

selkov

Well-known Member
Joined
Jan 26, 2004
Messages
787
I would like to delete all rows on a worksheet where cells in column c are either in the range of "0-70" and "85-125".

I have done similar with a specific value but never a range.
can this be done?
Any examples?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try next code

Code:
Sub DeleteRows()
Dim DelRg  As Range
Dim I  As Long, LR  As Long
Const WkCol As String = "C"
Const FR As Integer = 2
    LR = Cells(Rows.Count, WkCol).End(3).Row
    Set DelRg = Cells(LR + 1, WkCol)
    For I = FR To LR
        If (((0 < Cells(I, WkCol)) And (Cells(I, WkCol) < 70))) Then Set DelRg = Union(DelRg, Cells(I, WkCol))
        If (((85 < Cells(I, WkCol)) And (Cells(I, WkCol) < 125))) Then Set DelRg = Union(DelRg, Cells(I, WkCol))
    Next
    DelRg.EntireRow.Delete
'
End Sub
 
Upvote 0
This deleted everything. thought maybe it was the statements 0< / 85< that should have been 0>. / 85> . But that deleted everything too.
 
Upvote 0
We have to be clear about the limits, it is: 75 and not .75 neither /75 etc ...
 
Upvote 0
See here a data sample: Red values are deleted ...!
Of course data in column "C"

49
31
93
10
95
9
12
74
28
35
71
129
149
148

<tbody>
</tbody>
 
Last edited:
Upvote 0
Sorry, that still did not work It deletes everything. But I got it to work like this: [just tweaked the #'s in the range to work]

LR = Cells(Rows.Count, "A").End(xlUp).Row
For r = LR + 1 To 1 Step -1
ra = Range("C" & r)
If ra < 17 Then Rows(r).EntireRow.Delete
If ra > 19 Then Rows(r).EntireRow.Delete
Next
 
Last edited:
Upvote 0
You are good and I am not.
There is a BIG, BIG error, when deleting rows we must always start by the BOTTOM
Code:
Sub DeleteRows()
Dim DelRg  As Range
Dim I  As Long, LR  As Long
Const WkCol As String = "C"
Const FR As Integer = 2
    LR = Cells(Rows.Count, WkCol).End(3).Row
    Set DelRg = Cells(LR + 1, WkCol)
    For I = LR to FR step -1
        If (((0 < Cells(I, WkCol)) And (Cells(I, WkCol) < 70))) Then Set DelRg = Union(DelRg, Cells(I, WkCol))
        If (((85 < Cells(I, WkCol)) And (Cells(I, WkCol) < 125))) Then Set DelRg = Union(DelRg, Cells(I, WkCol))
    Next
    DelRg.EntireRow.Delete
'
End Sub
I apologize
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,310
Messages
6,124,188
Members
449,147
Latest member
sweetkt327

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