Thread: URGENT LOOP ?
View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Mike Mike is offline
external usenet poster
 
Posts: 3,101
Default URGENT LOOP ?

Dosen't work

"Don Guillett" wrote:

Try this

for i=cells(rows.count,"b").end(xlup).row to 1 step -1
'one line
if right(cells(i,2,5)="Total" and cells(i,3)<5 then rows(i).delete
next i


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Mike" wrote in message
...
Don My data looks like this I would like to delete receipt's where the
subtotal is less then 5
26-Sep-07 504326 4 'Delete
504326 Total 4 'Delete
27-Sep-07 504400 2 'Keep
27-Sep-07 504400 2 'Keep
27-Sep-07 504400 6 'Keep
27-Sep-07 504400 2 'Keep
504400 Total 12'Keep
28-Sep-07 504750 3 'Delete
504750 Total 3 'Delete
29-Sep-07 504823 4 'Delete
504823 Total 4'Delete
30-Sep-07 504983 4 'Delete
504983 Total 4'Delete


"Don Guillett" wrote:

something simpler

for i=cells(rows.count,"b").end(xlup).row to 1 step -1
'one line
if ucase(cells(i,5))="TOTAL" and cells(i,6)<5 then rows(i).delete
next i

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Mike" wrote in message
...
I have a sheet that is Subtotaled by Receipts #'s I'm trying to delete
Receipts that are less then 5
Please help
Sub deleterowtest()
Dim rngColB As Range
Dim ipointer As Long
Dim sSting As String
sSting = "Total"
'Change "B" to the column your data in in you are looking to find
Set rngColB = ActiveSheet.Range(Cells(1, "B"), Cells(Rows.Count,
"B").End(xlUp))

'Work backwards from bottom to top when deleting rows
With rngColB
For ipointer = .Rows.Count To 1 Step -1
If Right(.Cells(ipointer).Value, 5) = (sSting) And _
.Cells(ipointer).Offset(0, 1).Value < 5 Then
MsgBox .Cells(ipointer).Offset(0, 1).Value
'.Cells(ipointer).EntireRow.Delete
End If
Next ipointer
End With
End Sub