ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Making calculations down one column while moving down another (https://www.excelbanter.com/excel-programming/398899-making-calculations-down-one-column-while-moving-down-another.html)

JV

Making calculations down one column while moving down another
 
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

JW[_2_]

Making calculations down one column while moving down another
 
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 wrote:
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



JRForm

Making calculations down one column while moving down another
 
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

"JV" wrote:

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


JW[_2_]

Making calculations down one column while moving down another
 
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.
JRForm wrote:
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

"JV" wrote:

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



JRForm

Making calculations down one column while moving down another
 
JW,

Thanks for tip.

JR

"JW" wrote:

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.
JRForm wrote:
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

"JV" wrote:

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





All times are GMT +1. The time now is 03:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com