HI I am trying to add a sub column row under the last row I have data. Here's some information about my worksheet:
Name of current worksheet: Quantity Difference
The fourth worksheet in the whole workbook
Current Data range:K9-K19
This function will be in CommandButton1 in macro
I need to have the subtotal row appears at the bottom row but I can't leave space or doing by hand every time. I need a VBA code enable that if I have data in K9-K19,the sum is in K20. If I have K9-K100,the sum is in K101.
This is my current code but the excel shows a "9" range error everytime I ran. Please help!! Thank you!!
Private Sub CommandButton1_Click()
Dim lLastRow As Long
With Sheets("Sheet4") 'Quantity Difference
lLastRow = .Range("L" & .Rows.Count).End(xlUp).Row
.Range("K" & lLastRow + 1).Formula = "=Sum(K9:K" & lLastRow & ")"
End With
End Sub
Name of current worksheet: Quantity Difference
The fourth worksheet in the whole workbook
Current Data range:K9-K19
This function will be in CommandButton1 in macro
I need to have the subtotal row appears at the bottom row but I can't leave space or doing by hand every time. I need a VBA code enable that if I have data in K9-K19,the sum is in K20. If I have K9-K100,the sum is in K101.
This is my current code but the excel shows a "9" range error everytime I ran. Please help!! Thank you!!
Private Sub CommandButton1_Click()
Dim lLastRow As Long
With Sheets("Sheet4") 'Quantity Difference
lLastRow = .Range("L" & .Rows.Count).End(xlUp).Row
.Range("K" & lLastRow + 1).Formula = "=Sum(K9:K" & lLastRow & ")"
End With
End Sub