Why is my formula not working for the subtotal?

Jenaustin29

New Member
Joined
Oct 12, 2023
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
Selection.EntireRow.Delete
Worksheets("SalesComparison").Range("DC2") = WorksheetFunction.Subtotal(9, Range("dc4:dc" & Rows(Rows.Count).End(xlUp).Row))
Worksheets("SalesComparison").Range("Dd2") = WorksheetFunction.Subtotal(9, Range("dd4:dd" & Rows(Rows.Count).End(xlUp).Row))
Worksheets("SalesComparison").Range("Li2") = WorksheetFunction.Subtotal(9, Range("LI4:LI" & Rows(Rows.Count).End(xlUp).Row))
Worksheets("SalesComparison").Range("LJ2") = WorksheetFunction.Subtotal(9, Range("LJ4:LJ" & Rows(Rows.Count).End(xlUp).Row))


It gives me to sum just not using the subtotal function where when I filter it changes the total
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
VBA Code:
Selection.EntireRow.Delete

Dim lastRow As Long

With Worksheets("SalesComparison")
    lastRow = .Cells(.Rows.Count, "DC").End(xlUp).Row
    
    .Range("DC2").Formula = "=SUBTOTAL(9, DC4:DC" & lastRow & ")"
    .Range("DD2").Formula = "=SUBTOTAL(9, DD4:DD" & lastRow & ")"
    .Range("LI2").Formula = "=SUBTOTAL(9, LI4:LI" & lastRow & ")"
    .Range("LJ2").Formula = "=SUBTOTAL(9, LJ4:LJ" & lastRow & ")"
End With
 
Upvote 0
Solution

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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