Delete row if value between two numbers

pook_666

Board Regular
Joined
Aug 16, 2018
Messages
80
Hi magicians,

I'm trying to delete rows if the value in column E is between -0.01 and 0.01...unfortunately I can't just delete if it is simply 0 as there are rounding's to many millions after the decimal point so have to do between -0.01 and 0.01 to remove anything for 0.00.

I thought about just using the "and" between the IF statement as per below, but VBA doesn't like it.....any ideas? Thanks!

VBA Code:
    lrow2 = Cells(Rows.Count, "B").End(xlUp).Row
    For i = lrow2 To 1 Step -1
        If Cells(i, "E") >-0.01 and <0.01 Then
            Rows(i).Delete
        End If
    Next i
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

vcoolio

Well-known Member
Joined
Jun 29, 2014
Messages
1,057
Hello Pook_666,

A slight change to your code should work:-

VBA Code:
Sub Test()

Dim lrow2 As Long: lrow2 = Cells(Rows.Count, "B").End(xlUp).Row

        For i = lrow2 To 1 Step -1
                If Cells(i, "E") > -0.01 And Cells(i, "E") < 0.01 Then
                       Rows(i).Delete
                End If
        Next i
End Sub

I hope that this helps.

Cheerio,
vcoolio.
 
Solution

vcoolio

Well-known Member
Joined
Jun 29, 2014
Messages
1,057
You're welcome Pook_666. I'm glad to have been able to assist and thanks for the feed-back.

Cheerio,
vcoolio.
 

Watch MrExcel Video

Forum statistics

Threads
1,128,129
Messages
5,628,869
Members
416,347
Latest member
AT2021

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
Top