View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Delete entire row with a positive number

also Don's had no period in front of the cells or rows, so it would leave the
impression of working on Sheet1, but actually worked on the activesheet or if
in a sheet module, on the sheet containing the code. No problem if the
activesheet is sheet1 or sheet1 contains the code, but then you don't need
the with.

--
Regards,
Tom Ogilvy


"Die_Another_Day" wrote:

Close, yours would error out as you forgot the next statement, although
that wasn't my point for posting, I was trying to show th OP what was
wrong with her code and how to correct it.
Charles
Don Guillett wrote:
Isn't that the same as my post?

--
Don Guillett
SalesAid Software

"Die_Another_Day" wrote in message
oups.com...
Martha, the main problem is that as you delete a row, you end up
skipping the next row, for example if B2 = 5, and B3 = 5, first you
delete row 2, now B2 holds the value that was in B3 and you said to go
to "Next i" which means the original value from B3 never gets checked.
Also the syntax for the Cells object is backwards, Cells(2,i) where i =
6 refers to Row 2, Column 6. The best approach to deleting rows is to
move backwards through them:
Sub click()
Dim i as Integer
With Sheet1
For i = 6 to 2 Step -1
If .Range("B" & i) 0 Then .Rows(i).Delete
Next
End Sub

HTH

Charles Chickering

marthasanchez wrote:
How do I delete an enitre row based on one columns number. For example,
if
column A has a 5 then the entire row should be deleted and the formula
move
to the next row.
This is what i have, but it is siftong through columns.

Sub click()
Dim i As Integer
Sheet1.Select
Sheet1.Range("a2:b5").Select
For i = 2 To 6
Cells(2, i).Select
If Sheet1.Cells(2, i) 0 Then Sheet1.Rows(i).Delete
Next i
End Sub

PLEASE HELP