R
Rob
I have the code below that does what I want but seem untidy and I feel it
could be done in a cleaner way. This code runs and in columns K, L, R, S, T
and U it added a formula below the last row of data. As you'll see, the
code first finds the last row and RowCount is used in the formula.
Is there an easier way to achieve what I'm looking for and a way in which
would be easier to change in the future if needed?
Thansk, Rob
Sub Subtotal()
Dim RowCount As Long
Range("K1").Select
Range(Selection, Selection.End(xlDown)).Select
RowCount = Selection.Rows.Count
Range("K1").Select
Range("K" + CStr(RowCount + 2)).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" + CStr(RowCount) & "]C:R[-1]C)"
Range("L1").Select
Range("L" + CStr(RowCount + 2)).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" + CStr(RowCount) & "]C:R[-1]C1)"
Range("R1").Select
Range("R" + CStr(RowCount + 2)).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" + CStr(RowCount) & "]C:R[-1]C)"
Range("S1").Select
Range("S" + CStr(RowCount + 2)).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" + CStr(RowCount) & "]C:R[-1]C)"
Range("T1").Select
Range("T" + CStr(RowCount + 2)).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" + CStr(RowCount) & "]C:R[-1]C)"
Range("U1").Select
Range("U" + CStr(RowCount + 2)).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" + CStr(RowCount) & "]C:R[-1]C)"
End Sub
could be done in a cleaner way. This code runs and in columns K, L, R, S, T
and U it added a formula below the last row of data. As you'll see, the
code first finds the last row and RowCount is used in the formula.
Is there an easier way to achieve what I'm looking for and a way in which
would be easier to change in the future if needed?
Thansk, Rob
Sub Subtotal()
Dim RowCount As Long
Range("K1").Select
Range(Selection, Selection.End(xlDown)).Select
RowCount = Selection.Rows.Count
Range("K1").Select
Range("K" + CStr(RowCount + 2)).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" + CStr(RowCount) & "]C:R[-1]C)"
Range("L1").Select
Range("L" + CStr(RowCount + 2)).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" + CStr(RowCount) & "]C:R[-1]C1)"
Range("R1").Select
Range("R" + CStr(RowCount + 2)).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" + CStr(RowCount) & "]C:R[-1]C)"
Range("S1").Select
Range("S" + CStr(RowCount + 2)).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" + CStr(RowCount) & "]C:R[-1]C)"
Range("T1").Select
Range("T" + CStr(RowCount + 2)).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" + CStr(RowCount) & "]C:R[-1]C)"
Range("U1").Select
Range("U" + CStr(RowCount + 2)).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-" + CStr(RowCount) & "]C:R[-1]C)"
End Sub