Deleting entire rows based on criteria

suhi100

New Member
Joined
May 9, 2013
Messages
23
Hi,

I have an excel sheet with hunderds of rows but I only need to keep tho rows in which the value in column A is smaller than 8000.
I have found a code ,which deletes entire rows if they are empty, I guess it can be altered somehow to delete entire rows if the value in column A in that row is smaller than 8000.

Here is the code:

'Step1 Declare your variables

Dim myRange As range
Dim icounter As Long

'Step2 Define the target range

Set myRange = ActiveSheet.usedrange

'Step3 Start reverse looping through the range

For icounter = myRange.Rows.count To 1 Step -1

'Step4 If entire column empty delete it.

If Application.count(Rows(icounter).entirerow) = 0 Then
Rows(icounter).Delete
End If

'step5 Increment the counter down

Next icounter
End Sub


Hope you can help with this,thanks!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try this one
Code:
Sub DeleteValueWith_0_in_column_A()
Dim r As Long
For r = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1
If Cells(r, 1) = <8000 Then Rows(r).Delete
Next r
End Sub
 
Upvote 0
Hello again,

Just testing the code you have sent and is working great. There is only one thing that needs to be added to it because this macro not only deletes all the rows that satisfies the criteria Cells(r, 1) = <8000 Then Rows(r).Delete, but it deletes rows in which cells(r,1) contain text. So for example in cell A3 I have 8001 and in A2 I have the text TOTAL. The macro would delete both rows,but iI would like to keep the row in which the first column is text. Also, all the cells where the value is TEXT are actually merged cells and have different color than the cells with numbers. I was trying to add more if statements to the code but did not work...

Any ideas?

Cheers,

Suhi
 
Upvote 0

Forum statistics

Threads
1,216,160
Messages
6,129,215
Members
449,493
Latest member
JablesFTW

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