View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Nuno Nuno is offline
external usenet poster
 
Posts: 10
Default Deletion of rows in a column according to a given criteria

Hi everyone,

Hope you can help me with this. I've written a macro that searches every
cell in a given column for an empty cell (""), and deletes the row of that
cell. However, given that the sheets that will be used don't have equal
number of observations, the macro I've written checks every single until row
65536, even though, the cells might be empty because the the database has
reached its ends. The result is a slow macro.
Here goes the code:
Sub main_varcodes_correction()

cnt = 1
cnt1 = 0
hlp = 0
zero = 0
For cnt = 1 To 65536

cnt1 = cnt1 + 1

If Cells(cnt1, 7) = "" Then
Rows(cnt1).Select
Selection.Delete Shift:=xlUp
cnt1 = cnt1 - 1
hlp = hlp + 1
Else
hlp = 0
End If


If hlp = 100 Then
r = (cnt1 + 1) & ":" & "65536"
Rows(r).Select
Selection.Delete Shift:=xlUp
cnt = 65536
End If

Next cnt

End Sub

Does anyone know a way to improve the macro. it takes almost 3minutes to
process one file, and I have 200 plus to process...

Thanks,

Nuno