LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 89
Default help with loop to delete rows

Thank you for the tip on using the used range - I appreciate the help I
always get from this forum

"Vergel Adriano" wrote:

Christy,

Check the code below. Instead of using 3300 as the last row, you can
determine the last used row to make it more efficient. You also don't need
to select the cell to delete the row. But the most important thing is that
you need to go through the cells from bottom to top so you don't miss
anything.


Sub DeleteUnusedRows()
Dim i As Integer
Dim lLastRow As Long

lLastRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastC ell).Row

If lLastRow < 7 Then Exit Sub

For i = lLastRow To 7 Step -1
With Cells(i, 3)
If .Text < "Count required?" Then .EntireRow.Delete
End With
Next i
Range("a1").Select
End Sub


"Christy" wrote:

I have the following data and I am trying to make a loop to delete all row
except the ones that have the words 'Count Required' in column C

A B C D
UNIT NAME AUDIT WITHIN?
123 Main 0.19 YES
123 Main 0.43 YES
123 Main -13.44 NO
123 Main Count Required? YES
456 Smallville -25.77 NO
456 Smallville 95.76 NO
456 Smallville 23.42 YES
456 Smallville Count Required? YES
789 Anytown 8.04 YES

I tried the following loop which only deletes some of the rows. I have to
run it seveal times to get what I want. Can anyone tell what I am doing wrong
or offer a better way to accomplish my task?

Sub DeleteUnusedRows()
Dim i As Integer
For i = 7 To 3300 Step 1
Cells(i, 3).Select
If ActiveCell.Value < "Count required?" Then
ActiveCell.EntireRow.Delete
End If
Next i
Range("a1").Select
End Sub

 
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
How to Delete Rows in Excel In a Do Loop indraneel Excel Worksheet Functions 6 September 15th 06 09:51 AM
Excel loop to delete redudent rows [email protected] Excel Programming 6 September 13th 05 05:45 PM
Loop all sheetsand delete empty rows Sige Excel Programming 2 July 27th 05 12:22 PM
loop to delete rows... Froglegz Excel Programming 5 August 1st 04 09:56 PM
How do I delete rows and columns in With With End Loop? Bob Benjamin Excel Programming 3 November 16th 03 12:26 AM


All times are GMT +1. The time now is 09:08 AM.

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

About Us

"It's about Microsoft Excel"