two critera

  • Thread starter Thread starter ksnapp
  • Start date Start date
K

ksnapp

ok

I need a sub that will look down column F and if the value in there is
zero, will look in column A, if that cell is blank then I need to
delete the row

here is what I wrote, that doesn't work

Sub hatethissub()

For Each CELL In selection
If activecell.Value = 0 Then
If CELL.Offset(0, -5).Text = "" Then
EntireRow.Delete
End If
End If
Next
End Sub

it gets a runtime error "type mismatch" when it gets to the first if
 
with every one of these I get a type mismatch runtime error when it get
to the logical expressio
 
what type of data is in column F? numbers? letters? numbers and letters
formulas?

modify whatever code you are using to read

If CELL.Value = "0"

normally that makes no difference, but maybe you've got some odd kin
of data in there.

you might even try

If CELL.Value = EMPTY

Since if it is really a zero, excel will read it as EMPTY.

(using activecell in your earlier code was part of the problem, exce
loops through the selection, but it won't activate it unless you ask i
to... switching from activecell to CELL (or the name of your eac
statement) will have it reference the selection, not the activecell
which could be cell "A1" the whole time...)

finally, if all else fails, use the autofilter method, see:

http://www.rondebruin.nl/delete.htm#AutoFilte
 
the empty thing was the key and I didn't know that about active.cell.

Thank you all so muc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top