Delete a row based on more than one condtion

  • Thread starter Thread starter Opal
  • Start date Start date
O

Opal

I am using the following code to delete a row in a spreadsheet based
on the value (zero) in that row:

Sub RemoveZero()
Dim RngColAB As Range
Dim c As Long
Application.ScreenUpdating = False
Set RngColAB = Range("AB2", Range("AB" & Rows.Count).End(xlUp))
For c = RngColAB.Count To 1 Step -1
RngColAB(c).Value = Application.Trim(RngColAB(c))
If RngColAB(c).Value = 0 Then _
RngColAB(c).EntireRow.Delete
Next c
Application.ScreenUpdating = True
End Sub

How can I modify it so that it looks to two columns where both rows
have to have a zero value so that the row can be deleted?
 
change the line:
If RngColAB(c).Value = 0 Then _
to
If RngColAB(c).Value = 0 And Application.Trim(RngColAB(c).Offset(0,
7).value) = 0 Then _
where the 7 is a value I've chosn at random representing 7 cells to the
right of your cell being tested for 0. A 1 would be one cell to the right, a
-1 would be one cell to the left etc. etc.
(not tested).
 
Try this:

RngColAB(c).offset(0,1) 'One cell to the right
RngColAB(c).offset(1,0) 'One cell below

HTH,
Barb Reinhardt
 

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