Question about adding sub total in last row plus one. Please help!!

Cicyhua

New Member
Joined
Aug 27, 2014
Messages
6
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
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,224,387
Messages
6,178,294
Members
452,838
Latest member
TGirl66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top