Subtotal with Macro

Bookmaster

Board Regular
Joined
Mar 22, 2014
Messages
85
Office Version
  1. 2021
Platform
  1. Windows
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.
Is there any help please?

BM
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
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?
Can somebody help me please?

BM
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,518
Messages
6,119,996
Members
448,935
Latest member
ijat

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