Row deleting script problem

J

jessica

Hello Guys!
I have made a script for deleting rows where column A value
is greater than 1280.
It works fine but it will loop endlessly. What can I do about it?
If I delete the "RowNumber = RowNumber - 1" then it does'nt
work properly.

TotalRows = Application.CountA(ActiveSheet.Range("A:A"))
Cells(1, 1).Select
For RowNumber = 1 To TotalRows
If Cells(RowNumber, 1).Value > 1280 Then
Cells(RowNumber, 1).Select
Selection.EntireRow.Delete
RowNumber = RowNumber - 1
End If
Next

Please help me,
Little Jessica
 
R

Roger

Jessica, try this

Public Sub DeleteHighRows()
Dim lngLastRow As Long
Dim lngTemp As Long

lngLastRow = ActiveSheet.Range("A65500").End(xlUp).Row
Application.ScreenUpdating = False
For lngTemp = lngLastRow To 1 Step -1
If ActiveSheet.Cells(lngTemp, 1).Value > 1280 Then
ActiveSheet.Rows(lngTemp).Delete
Next lngTemp
Application.ScreenUpdating = True
End Sub

Regards

Rog
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top