MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

if condition with negative value

  Asked By: Molly    Date: Feb 02    Category: MS Office    Views: 2394

I am trying to write a macro that removes rows that have a value less
than -1 in all columns C, D, E but I loose all the rows that have a
negative value (even if it is between 0 and -1) in all the three columns.
E.g. If I have a row:
idnumber idname -1.1 -0.3 -2.9
It is removed even though the value -0.3 is not less then -1?

Here is my code, can anyone please help me to explain/show how to do
this properly?

Sub RemoveBG()
totalrows = ActiveSheet.UsedRange.Rows.Count

For Row = totalrows To 1 Step -1
If (Cells(Row, 3).Value < -1 And Cells(Row, 4).Value < -1 And
Cells(Row, 5).Value < -1) Then
End If
Next Row

End Sub



1 Answer Found

Answer #1    Answered By: Luann Schmidt     Answered On: Feb 02

I just tried it and it only deleted the rows  I would have expected it to.
Specifically, it didn't delete a row  with your three numbers in it.

Are you sure that this is the exact code  that is running?

Didn't find what you were looking for? Find more on if condition with negative value Or get search suggestion and latest updates.