PDA

View Full Version : Solved: Delete Any Numbers that are less than 1



Djblois
02-01-2007, 10:44 AM
I want to be able to delete any numbers in a column that are fractions less than the #1. Is this possible?

Along the same lines I want to be able to delete all the numbers in a column that are less than 1 cent different than the line above it. Also is this possible?

Djblois
02-01-2007, 10:50 AM
I think I figured them out. If I am right then I am stupid for having to ask.

Djblois
02-01-2007, 10:53 AM
If Cells(i, "C") = Cells(i + 1, "C").Value Then
If Range("K" & i).FormulaR1C1 = "=(RC[-5]-R[1]C[-5])/7" < 1 Then
Range("K" & i).FormulaR1C1 = ""
Else
Range("K" & i).FormulaR1C1 = "=(RC[-5]-R[1]C[-5])/7"
End If
End If

This is the code I am using. However it is deleting all of range k. Well it isn't deleting K but it isn't calculating any of them.

Djblois
02-01-2007, 10:59 AM
VBA:
If Cells(i, "C") = Cells(i + 1, "C").Value Then If Range("K" & i).FormulaR1C1 = "=(RC[-5]-R[1]C[-5])/7" < 1 Then Range("K" & i).FormulaR1C1 = "" Else Range("K" & i).FormulaR1C1 = "=(RC[-5]-R[1]C[-5])/7" End If End If

VBA tags courtesy of www.thecodenet.com (http://www.thecodenet.com/)


This is the code I am using. However it is deleting all of range k

lucas
02-01-2007, 11:01 AM
Threads merged.....????

Norie
02-01-2007, 11:22 AM
I'm sorry but your comparison here makes no sense.

If Range("K" & i).FormulaR1C1 = "=(RC[-5]-R[1]C[-5])/7" < 1 Then

This will not look at the value in the cell.

First it'll see if the formula in the cell is =(RC[-5]-R[1]C[-5])/7.

If it is it'll return TRUE, which it will check to see if it's less than one.

I'm not sure exactly how VBA will handle that.

Djblois
02-01-2007, 11:25 AM
ok that explains why it doesn't work but now how do I use that to figure out if that formula is less than 1 then do this?

Djblois
02-01-2007, 11:31 AM
ok this is what I got working:

Range("K" & i).FormulaR1C1 = "=(RC[-5]-R[1]C[-5])/7"
If Range("K" & i) < 1 Then
Range("K" & i).ClearContents
End If

Djblois
02-01-2007, 11:36 AM
Now I am going to try and work on the second part

Djblois
02-01-2007, 11:45 AM
THis is what I have for the second part. However, I just figured out I need to clear the contents of any that are between 1 cent and -1 cent. How do I do that?

Range("J" & i).FormulaR1C1 = "=RC[-2]-R[1]C[-2]"
If Range("J" & i) < 0.01 Then
Range("J" & i).ClearContents
End If

Djblois
02-01-2007, 12:32 PM
This is what I am using for the second part:

If Range("J" & i) < 0.01 & Range("J" & i) > -0.01 Then
Range("J" & i).ClearContents
End If

And it isn't working

Bob Phillips
02-01-2007, 12:51 PM
You should be comparing both (AND) not concatenating them (&)



If Range("J" & i) < 0.01 AND Range("J" & i) > -0.01 Then
Range("J" & i).ClearContents
End If


But you can do without either





If Abs(Range("J" & i).Value) < 0.01 Then
Range("J" & i).ClearContents
End If

Djblois
02-01-2007, 01:05 PM
Thank you that worked