I have a macro that works, but is actually slower than when I did it by hand. There are about 10000 rows that have to be looped thru and the purpose is to delete rows that meet certain conditions. Basically what it does is put the word "DEL" or "KEEP" at the end of each row and then loops thru and deletes the "DEL" rows. WHen I did by hand I would sort and then find the break and then delete a big chunk without having to loop thru. So, is there a way to improve the efficiency of the code below, or do I need to go about writing it differently.
Code:
sub
Range("Z1").FormulaR1C1 = "Disposition"
Range("Z2").FormulaR1C1 = _
"=IF(RC[-12]=""X"",""DEL"",IF(RC[-4]=""Medically Complex"", ""KEEP"",IF(OR(RC[-8]=""foster home"",RC[-8]=""child caring ag"",RC[-8]=""c. licensed private child care"",RC[-8]=""e. group homes"",RC[-8]=""education"",RC[-8]=""f. residential facility"",RC[-8]=""g. children's psychiatric hosp"",RC[-8]=""independent living location"",RC[-8]=""k. independent living"",RC[-8]=""m. detention facility"",RC[-8]=""long term care facility"",RC[-8]=""medical providers"",RC[-8]=""hospitals - medical"",RC[-8]=""""),""KEEP"",""DEL"")))" & _
""
Range("Z2").AutoFill Destination:=Range("z2:z" & lastRow)
Columns("Z:Z").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
For RowtoTest = Cells(Rows.Count, 26).End(xlUp).row To 2 Step -1
With Cells(RowtoTest, 26)
If .Value = "DEL" _
Then _
Rows(RowtoTest).EntireRow.Delete
End With
Next RowtoTest
Range("Z:Z").Delete Shift:=xlToLeft
Cells.Select
Cells.EntireColumn.AutoFit
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\jtreece\Desktop\058.xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
Application.DisplayAlerts = True
end sub
Last edited by a moderator: