View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
JMay JMay is offline
external usenet poster
 
Posts: 422
Default Macro For Deleting Cells Containing A Number

Another modification (to speed it up) would be to after each trip Up the column
and if deletion takes place have
the macro recalculate the "lastrow" integer. At present, it is agter each trip
Up the column returning to Row 11 when in fact there is no data in row 11, 10,
9, 8 --- if 4 rows have already been deleted.
I changed your reference to lastrow to BegLastRow
and then put within the For Next statement a Recalculation
statement and a new Reference NewLastRow to
eliminate revisiting already deleted rows.

Sub Foo()
Dim arr As Variant
Dim i As Long
Dim BlastRow As Long
Dim rng As Range
Dim cell As Range
Dim c As Long
arr = Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9")
BegLastRow = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
Set rng = Range("A1:A" & BegLastRow)
For i = LBound(arr) To UBound(arr)
Application.Calculate
NewLastRow = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
c = NewLastRow
Do While c 0
If InStr(1, Range("a" & c), arr(i)) Then
Rows(c).EntireRow.Delete
Else
End If
c = c - 1
Loop
Next
End Sub

Logically, this involves fewer passes. Gary Did an excellent job on this
incidently; Thanks Gary...

HTH,

Jim May

"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
adding this would make it a little faster

Application.ScreenUpdating = False

code

Application.ScreenUpdating = true
--


Gary


"brazen234" wrote in
message ...

-Yngve
I ran your macro but it did not delete the rows with numbers. The list
was the same after running it.

-Gary Keramidas
Thanks, your macro does work! But can it be faster ? My lists are in
the tens of thousands.

-Toppers
Thanks but there are also occurences of the last character being alpha
with numbers inbetween.


--
brazen234
------------------------------------------------------------------------
brazen234's Profile:
http://www.excelforum.com/member.php...fo&userid=9952
View this thread: http://www.excelforum.com/showthread...hreadid=501478