Making calculations down one column while moving down another

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

First I need to move down a column starting at A5 until there is no data in
a row to identify the numbers of rows . As I am moving down the row, I need
to calculate cell C5 = M5-M4. Then cell C6=M6-M5 and so on.

Thanks in advance,
JV
 
To keep the formula intact:
Sub testHere()
For i = 5 To Cells(Rows.Count, 1).End(xlUp).Row
Cells(i, 3).FormulaR1C1 = "=RC[10]-R[-1]C[10]"
Next i
End Sub

To not keep the formula:
Sub testAgain()
For i = 5 To Cells(Rows.Count, 1).End(xlUp).Row
Cells(i, 3).Value = Cells(i, 13).Value - _
Cells(i, 13).Offset(-1, 0).Value
Next i
End Sub
 
JV,
Try this
Sub JV()

Range("A5").Select
If ActiveCell <> "" Then
Do Until ActiveCell = ""
'c5=m5-m4
ActiveCell.Offset(0, 2) = ActiveCell.Offset(0, 12) -
ActiveCell.Offset(-1, 12)
ActiveCell.Offset(1, 0).Select
Loop
Else
Exit Sub
End If
End Sub
 
JR, while your code may produce the correct results, making selections
like that is generally considered a bad coding practice and should be
avoided if at all possible. In this case, there is no need to make
selections of any kind.
 
JW,

Thanks for tip.

JR

JW said:
JR, while your code may produce the correct results, making selections
like that is generally considered a bad coding practice and should be
avoided if at all possible. In this case, there is no need to make
selections of any kind.
 

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