delete rows within a specific range macro

G

GraduatePlease09

Hi, I wanted to set up a macro which can delete rows within a certain range.
For example I want to delete all rows that have values in column B between
350 and 650. I also want to delete rows that have values below 250 and above
850 (I have the codes for these, but it would be great to incorporate all 3
into 1 macro)

Thanks!
 
J

Jacob Skaria

Please try this and feedback

Sub Macro()
Dim lngLastRow, lngRow, varValue
lngLastRow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row
For lngRow = lngLastRow To 1 Step -1
varValue = Range("B" & lngRow).Value
If varValue < 250 Or varValue > 850 Or (varValue > 350 And varValue < 650)
Then
ActiveSheet.Rows(lngRow).Delete
End If
Next
End Sub

If this post helps click Yes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top