# Subtotal with Macro

#### Bookmaster

##### Board Regular
Hello,

I am desperate now. I spent last 4 hours trying to solve one SUBTOTAL function but it won't work. I have one workbook with just one sheet. In that sheet I have a lot of data. Now I need to put Subtotal that will make sum of all numbers that I have in row "H" starting from "H2" up to the end of row where I have data. End of row may vary and I never know which cell will be the last cell.

BM

### Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

#### Bookmaster

##### Board Regular
I manage to find something over net for SUM (not for subtotal) but that might be a start.
Code looks like this:

"
LASTROW = ThisWorkbook.Sheets("Sheet1").Cells(Rows.Count, 7).End(xlUp).Row
ThisWorkbook.Sheets("Sheet1").Range("G" & LASTROW + 1) = Application.WorksheetFunction.Sum(ThisWorkbook.Sheets("Sheet1").Range("G2:G" & LASTROW))
End Sub"

But it doesn't do the job. What I am doing wrong?

BM

#### Bookmaster

##### Board Regular
For everyone that might need it, this code is:

"Range("H2").Select
Cells(Rows.Count, "H").End(xlUp).Offset(1).Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R2C:R[-1]C)"
End Sub"

BM

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,164,626
Messages
5,838,438
Members
430,548
Latest member
hh_dh2001

### 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.

### Which adblocker are you using?

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

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