Delete row if cell value is < 25000000

ddwestenskow

New Member
Joined
Jul 11, 2008
Messages
10
Hi All,

I am trying to delete all rows where Column AB contains a number smaller than 25,000,000. While there are lots of threads on the subject I have not been able to find anything that works.

I have manipulated some code that I got from another post
HTML:
http://www.mrexcel.com/forum/showthread.php?t=191042&highlight=delete+row+based+cell
I am sure that the problem has something to do with the formating of the < 25000000 part of the code, I dont see any other reason why it would not work as written. I have formated the cells in AB as numbers using commas.

Rich (BB code):
Sub DeleteRowsFromBottom()
Dim i As Long, LastRow As Long
    Application.ScreenUpdating = False
        'finds last used row in column A
        LastRow = Range("AB65536").End(xlUp).Row
        'begin loop to check each row
        For i = LastRow To 2 Step -1
 
        'if cell < 25000000 delete
        If Mid(Cells(i, "AB"), 8, 7) < 25000000 Then Rows(i).Delete
 
    Next i
Application.ScreenUpdating = True
End Sub

Thanks in advance for any help.

-Dawson
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Try

Code:
Sub DeleteRowsFromBottom()
Dim i As Long, LastRow As Long
    Application.ScreenUpdating = False
        'finds last used row in column A
        LastRow = Range("AB" & Rows.Count).End(xlUp).Row
        'begin loop to check each row
        For i = LastRow To 2 Step -1
 
        'if cell < 25000000 delete
        If Cells(i, "AB").Value < 25000000 Then Rows(i).Delete
 
    Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
You are welcome! The change that made it work was

Code:
        If Cells(i, "AB").Value < 25000000 Then Rows(i).Delete

I only changed this

Code:
        LastRow = Range("AB" & Rows.Count).End(xlUp).Row

to ensure that it would function correctly in XL 2007 where there could be more than 65,536 rows of data.
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,891
Members
449,194
Latest member
JayEggleton

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