I need a way to sum the cells in a column that have been created in a variable manner. In the code I have attached I'm thinking I can insert an if statement that does this when the for loop has finished. Say the for loop runs 3 times I would need the cells in column K to sum sequentially. IE on the bottom most row, K would just be the value of J in the same row. In the 2nd from the bottom row, K would be the sum of column J in both rows. In the 3rd from bottom (top row), K would be the sum of column J, rows 1-3. Is there a way to do this? I think it's beyond my skill level.
If I didn't do it this way, once the rows have been created I could go in manually and enter the formula in the first cell =sum(J1:J$3) and then drag down to autocomplete. Can this be done with code so it's automated and doesn't have to necessarily be 3 rows?
If I didn't do it this way, once the rows have been created I could go in manually and enter the formula in the first cell =sum(J1:J$3) and then drag down to autocomplete. Can this be done with code so it's automated and doesn't have to necessarily be 3 rows?
Code:
Range("C15").Select 'set active cell to first catalyst
For j = 1 To Unit1 'loops for each row that needs to be created
Cat1.Select
Selection.Copy
Selection.Insert Shift:=xlDown
' If j = Unit1 Then
' ActiveCell.Offset(0, 8).Formula = "=sum(ActiveCell.Offset(0,8))"
'
Next j
For j = 1 To Unit2
Cat2.Select
Selection.Copy
Selection.Insert Shift:=xlDown
Next j
For j = 1 To Unit3
Cat3.Select
Selection.Copy
Selection.Insert Shift:=xlDown
Next j