PDA

View Full Version : Solved: Formula if Product is the same as above



Djblois
01-25-2007, 03:14 PM
I am trying to use the loop now to put a formula in "i" column only if the Product (Column C) is the same as the one below it


For i = To finalrow
If Cells(i, "C") = Cells(i - 1, "C").Value Then
Range("I:I" & i).FormulaR1C1 = "=RC[-2]-R[1]C[-2]"
Cells(i, "C").EntireRow.delete
Else
End If
Next


For some reason it will not work. It is giving me an error on the Formula line.

Djblois
01-25-2007, 03:21 PM
I even tried

For i = 2 To finalRow
If Cells(i, "C") = Cells(i - 1, "C").Value Then
Cells(i, "G").Formula = Cells(i, "G") - Cells(i + 1, "G")
Else
End If
Next

Djblois
01-25-2007, 03:35 PM
Corrected if it is the same as below it.

Here is the code now:

For i = 2 To finalRow
If Cells(i, "C") = Cells(i + 1, "C").Value Then
Cells(i, "G").Formula = Cells(i, "G") - Cells(i + 1, "G")
Else
End If
Next

Bob Phillips
01-25-2007, 04:39 PM
You keep adding an unnecessary Else, it is only required if you want to do something in the else.


For i = 2 To finalRow
If Cells(i, "C") = Cells(i + 1, "C").Value Then
Range("I" & i).FormulaR1C1 = "=RC[-2]-R[1]C[-2]"
End If
Next

Djblois
01-25-2007, 05:52 PM
Thank you xld but that doesn't correct the problem

Bob Phillips
01-26-2007, 03:24 AM
So what does it do, what do you want it to do?

Djblois
01-26-2007, 04:41 AM
It doesn't insert a formula in the "I" column for some reason. I want it to insert a formula in the "i" column to subtract the qty "G" column when the "C" Product is the same as the one below it.

Djblois
01-26-2007, 06:22 AM
xld,

Sorry, I got it to work thank you for all your support