Thread: Loop & Delete
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
Sandy Mann Sandy Mann is offline
external usenet poster
 
Posts: 2,345
Default Loop & Delete

"jenna" wrote in message
...

Do i have to place my cursor at the bottom of the column?

You don't have to place the cursor any where in particular

My apologies, I failed to notice that you asked the procedure to look at
Column B - I really should learn how to read!

Use the Macro:

Sub DeleteIt()
Dim Starter
Dim c As Long

Starter = Cells(Rows.Count, 2).End(xlUp).Row

For c = Starter To 1 Step -1
If Left(Cells(c, 2).Value, 5) = "Total" Then
Range(Cells(c, 2), Cells(c + 1, 2)).EntireRow.Delete
End If
Next c

End Sub


In this line:
Starter = Cells(Rows.Count, 2).End(xlUp).Row
the row number of the last filled cell in column 2 (ie Column B) is loaded
in the the variable *Starter*

this number is then used as the start of the loop
For c = Starter To 1 Step -1
which then steps UP through the column looking for a cell with *Total* in
it.

Also how do i delete the previous row too


You originally said:
first five letters = "Total" and the next row


the range in:
Range(Cells(c, 2), Cells(c + 1, 2)).EntireRow.Delete

is the row in which *Total* was found *and* the row below it
ie Cells(c, 2) is the cell in which *Total* was found and Cells(c + 1, 2) is
the next cell down (ie row c+1)

If you do want the *previous row* to be deleted then change the line then
post back again.
..

--
HTH

Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings


with @tiscali.co.uk


"jenna" wrote in message
...


Thanks so far

Do i have to place my cursor at the bottom of the column?
Also how do i delete the previous row too


thaks