I am trying to write a macro in excel 2010 that will go through all the cells in column L which is filled with numbers, if the cell number is between -1 and 1 I want to delete the entire row.
Right now my macro is deleting everything except numbers that are between -1 and 1. When I switch the <> signs around it deletes everything. Can you help me know what the correct code is?
Sub Delete_Rows()
Dim rows As Range, cell As Range, value As Long
Set cell = Range("L2")
Do Until cell.value = ""
value = Val(cell.value)
If (value < -1 Or value > 1) Then
If rows Is Nothing Then
Set rows = cell.EntireRow
Else
Set rows = Union(cell.EntireRow, rows)
End If
End If
Set cell = cell.Offset(1)
Loop
If Not rows Is Nothing Then rows.Delete
End Sub
Right now my macro is deleting everything except numbers that are between -1 and 1. When I switch the <> signs around it deletes everything. Can you help me know what the correct code is?
Sub Delete_Rows()
Dim rows As Range, cell As Range, value As Long
Set cell = Range("L2")
Do Until cell.value = ""
value = Val(cell.value)
If (value < -1 Or value > 1) Then
If rows Is Nothing Then
Set rows = cell.EntireRow
Else
Set rows = Union(cell.EntireRow, rows)
End If
End If
Set cell = cell.Offset(1)
Loop
If Not rows Is Nothing Then rows.Delete
End Sub