Hello,
I need some help with a macro loop written in Excel 2007. The macro starts at the bottom of a list of data. Rows have been inserted into the data to build in total lines; these lines are notated as "New". The loop works it's way up through the data, adding in the data for totals for each "New" row.
The problem occurs with the two formulas to add sums to the total lines. I've tried my best to write the code to sum whatever is above the total line up until the next blank cell. (The next blank cell is the next total row.)
For some reason the formula appears to be using the same number of rows for each line as was in the first line it was ran on. For example, if the first total line only has 1 row of data, the formula only sums one line for the rest of the total lines.
Now for the strange part, if I just pick another total line and step through the macro on that line, it works correctly.
Any suggestions please?
Thank you in advance!!!
The Wonky Loop Code:
'Make Totals
Do While Not IsEmpty(ActiveCell)
If (ActiveCell) = "New" Then
ActiveCell.Offset(0, -11).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 2).Select
With ActiveCell
.Formula = "=SUM(" & .Offset(0, 0).End(xlUp).Address(0, 0) _
& ":" & .Offset(-1, 0).Address(0, 0) & ")"
End With
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 1).Select
With ActiveCell
.Formula = "=SUM(" & .Offset(0, 0).End(xlUp).Address(0, 0) _
& ":" & .Offset(-1, 0).Address(0, 0) & ")"
End With
ActiveCell.Offset(0, 1).Select
End If
ActiveCell.Offset(-1, 0).Select
Loop
I need some help with a macro loop written in Excel 2007. The macro starts at the bottom of a list of data. Rows have been inserted into the data to build in total lines; these lines are notated as "New". The loop works it's way up through the data, adding in the data for totals for each "New" row.
The problem occurs with the two formulas to add sums to the total lines. I've tried my best to write the code to sum whatever is above the total line up until the next blank cell. (The next blank cell is the next total row.)
For some reason the formula appears to be using the same number of rows for each line as was in the first line it was ran on. For example, if the first total line only has 1 row of data, the formula only sums one line for the rest of the total lines.
Now for the strange part, if I just pick another total line and step through the macro on that line, it works correctly.
Any suggestions please?
Thank you in advance!!!
The Wonky Loop Code:
'Make Totals
Do While Not IsEmpty(ActiveCell)
If (ActiveCell) = "New" Then
ActiveCell.Offset(0, -11).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 2).Select
With ActiveCell
.Formula = "=SUM(" & .Offset(0, 0).End(xlUp).Address(0, 0) _
& ":" & .Offset(-1, 0).Address(0, 0) & ")"
End With
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = _
"=R[-1]C"
ActiveCell.Offset(0, 1).Select
With ActiveCell
.Formula = "=SUM(" & .Offset(0, 0).End(xlUp).Address(0, 0) _
& ":" & .Offset(-1, 0).Address(0, 0) & ")"
End With
ActiveCell.Offset(0, 1).Select
End If
ActiveCell.Offset(-1, 0).Select
Loop