I have a worksheet called "Pr", and a table in "Pr" called "Table1".
Size of "Table1" can be changed at anytime. So I wrote a sub "subtotal" for dynamically puting a SUM formula into the third last cell in "Table1" column 12 to sum all the cells' values above.
But when I tried to run it, how come no formula was added to the cell?
Size of "Table1" can be changed at anytime. So I wrote a sub "subtotal" for dynamically puting a SUM formula into the third last cell in "Table1" column 12 to sum all the cells' values above.
But when I tried to run it, how come no formula was added to the cell?
Code:
Public Sub subtotal()
Dim subtotal As Range
With Pr.ListObjects("Table1")
Set subtotal = .ListColumns(12).DataBodyRange.Offset(1, 0). _
Resize(.DataBodyRange.Rows.count - 3).End(xlUp)
End With
subtotal.Formula = "=SUM(M15:M" & subtotal.row - 1 & ")"
End Sub