Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Deletion of rows in a column according to a given criteria

The following will work on column A where less than 50000 rows are used, the
trick is in testing the row number of Activecell.end(xldown)


Range("A1").Select
Do Until ActiveCell.End(xlDown).Row 50000
If ActiveCell = "" Then
Rows(ActiveCell.Row).Delete
Else
ActiveCell.Offset(1, 0).Select
End If
Loop




"Nuno" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Deletion of rows in a column according to a given criteria

and obviously it will work uch quicker with screenupdating turned off, and
quicker still if you go down the column using offset(i,0) rather than
literally selecting the cell!

"Stuart" wrote in message
...
The following will work on column A where less than 50000 rows are used,
the trick is in testing the row number of Activecell.end(xldown)


Range("A1").Select
Do Until ActiveCell.End(xlDown).Row 50000
If ActiveCell = "" Then
Rows(ActiveCell.Row).Delete
Else
ActiveCell.Offset(1, 0).Select
End If
Loop




"Nuno" wrote in message
...
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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Deletion of rows in a column according to a given criteria

Instead of
For cnt = 1 To 65536
Try
For cnt = 1 To Activesheet.UsedRange.Rows.Count

This will only go through the rows to the last one with data in it.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting rows meeting certain criteria in a particular column tsraj Excel Discussion (Misc queries) 1 April 1st 10 07:58 PM
Count NonBlank Rows with Criteria in another column [email protected] Excel Worksheet Functions 7 May 9th 09 03:04 AM
Sum specific column rows based on 2 different column criteria Jack Excel Worksheet Functions 3 October 9th 08 05:03 PM
Countings rows based on column criteria Steve Excel Discussion (Misc queries) 2 April 19th 07 09:31 AM
Combine deletion Criteria gmunro Excel Programming 2 March 11th 05 05:32 PM


All times are GMT +1. The time now is 01:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"