Hey all, I have an excel sheet that pulls data from a database.
How can I get column C cells to have the formula =A<row number>-(B<row number>/10)
IF A and C are not the same value, if they are...I want it to make the formula exclude the /10.
Printable View
Hey all, I have an excel sheet that pulls data from a database.
How can I get column C cells to have the formula =A<row number>-(B<row number>/10)
IF A and C are not the same value, if they are...I want it to make the formula exclude the /10.
I'm not sure what you are really after here... you say that if A and C are the same, but as C is a calculation that involves A, the /10 will be irrelevant when they are equal (as it means that B is 0).
Sorry, I meant if A AND B are not the same
In cell C2:
..then copy & paste to the rest of CCode:=If(A2=B2, A2-B2, A2-(B2/10)
Replace "Sheets1" with the name of the relevant sheet.
This will only put the values in Column C. In case you want to put formulas in Column C then use the formula given by SI and put it in the above code...Code:Option Explicit
Sub Test()
Dim I
I = 1
'loop to ensure that the formula is put in the cells till where
'the data is in Column B
Do While Len(Trim(Sheets("Sheets1").Range("B" & I).Value)) <> 0
If Sheets("Sheets1").Range("A" & I).Value = _
Sheets("Sheets1").Range("B" & I).Value Then
'C = A - B if if A = B
Sheets("Sheets1").Range("C" & I).Value = _
Sheets("Sheets1").Range("A" & I).Value - _
Sheets("Sheets1").Range("B" & I).Value
Else
'C = A - (B/10) if A<>B
Sheets("Sheets1").Range("C" & I).Value = _
Sheets("Sheets1").Range("A" & I).Value - _
(Sheets("Sheets1").Range("B" & I).Value / 10)
End If
I = I + 1
Loop
End Sub