delete row macro question....

mdcampbell1

New Member
Joined
Jul 17, 2007
Messages
4
vb code question. i am trying to understand how to get a macro using vb to:
if i have a column of numbers, go through the whole column and identify any number that is less than say 10,000 and then select the entire row that number is on and delete the entire row. continue the process through the entire column. also, some cells in the column will be blank (delete), words (delete), and symbols such as # (delete).

i'm a relative novice here so any help would be appreciated.

Thanks,
MDC
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Something like

Code:
Sub dl()
Dim lastrow As Long, MyCol As Integer, i As Integer, x As Variant
Application.ScreenUpdating = False
Application.Calculation = xlManual
MyCol = 1 ' change to suit
lastrow = Cells(Rows.Count, MyCol).End(xlUp).Row
For i = lastrow To 1 Step -1
    x = Cells(i, MyCol).Value
    If x < 10000 Or Not IsNumeric(x) Or x = "" Then Cells(i, MyCol).EntireRow.Delete
Next i
Application.ScreenUpdating = True
Application.Calculation = xlAutomatic
End Sub

Edit: changed lastrow= to refer to MyCol.
 
Upvote 0
Does something like this do the trick... I am assuming that your first line of data is headers and I am checking column A in this code

Code:
Sub Test()
Dim lastrow As Long, firstrow As Long, r As Long, Ce As Range

Application.ScreenUpdating = False
With ActiveSheet.UsedRange
    firstrow = .Cells(1).Row + 1
    lastrow = .Cells(.Cells.Count).Row
End With

For r = lastrow To firstrow Step -1
    Set Ce = Cells(r, 1)
    If (Not IsNumeric(Ce.Value)) Or (Ce.Value < 10000) Then Ce.EntireRow.Delete
Next r
Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,986
Members
448,538
Latest member
alex78

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