Macro for deleting rows with positive numbers

lgerjets

New Member
Joined
Dec 4, 2009
Messages
18
I am looking for a Macro that would do the following: delete rows if the row contains a positive number? Example: "if a row has a positive number in column D then delete that row".

I have hundreds of rows that are sorted a certain way and don't want to sort them differently, just delete the rows with positive numbers.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Delete the row if there is a positive number anywhere within the row or only if the positive number is in column D ?
 
Upvote 0
  • Select column D
  • Select from the menu Data\ Filter\ AutoFilter
  • This will put a drop down list in D1
  • Select Custom from the D1 drop down list
    • Show rows where: Greater than 0
  • This will show only the rows with positive numbers in column D
  • Select all the visible rows and delete
  • Select Autofilter from the menu again to turn it off
  • Your results will not have been re-sorted
 
Upvote 0
I actually have something in column A that sorts out 5 different groups that I am working with and when I do that autofilter it takes away that grouping.
 
Upvote 0
Try
Code:
Sub rempos()
Dim lr As Long, r As Long
lr = Cells(Rows.Count, "D").End(xlUp).Row
    For r = lr To 1 Step -1
        If Range("D" & r).Value > 0 Then
            Rows(r).Delete
        End If
    Next r
End Sub
 
Upvote 0
Hello,

I also need a macro to delete all rows that contain positive numbers.

Ex: below are rows. the macro should check if all cells have positive numbers and delete them. Below the first cell is with negative therefore must stay.

<colgroup><col width="114"><col width="70"><col span="2" width="84"><col width="42"></colgroup><tbody>
[TD="class: xl63, width: 114"]-186[/TD]
[TD="class: xl63, width: 70"] [/TD]
[TD="class: xl63, width: 84"]77376[/TD]
[TD="class: xl63, width: 84"]39892[/TD]
[TD="class: xl63, width: 42"]2
[/TD]

</tbody>
Thank you very much for the support.
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,777
Members
452,942
Latest member
VijayNewtoExcel

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