Error in computed Subtotal in Range

airforceone

Board Regular
Joined
Feb 14, 2022
Messages
201
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
hi again,
I'm using set of VBA but does not compute the range properly! what seems to be the problem? i shall implement it in a loop sequence but the second computation is a bit off

VBA Code:
    Range("A2:M" & LastRow).AutoFilter 1, "=" & "*DAMAGE TO PROPERTY"
    Range("B10") = WorksheetFunction.Subtotal(9, Range("B2:B14"))
    Range("C10") = WorksheetFunction.Subtotal(9, Range("C2:C14"))
    Range("D10") = WorksheetFunction.Subtotal(9, Range("D2:D14"))
    Range("B1").AutoFilter 'Turn autofilter Off

XXXXXXXXXXXXXX UCPER DATA.xls
ABCD
1PARTICULARRURALURBANCITY
2PORCH8
3VERANDA8
4ROOF1
5DAMAGE TO PROPERTY631
6MULTIPLE DAMAGE TO PROPERTY02
7REPAIRED32
8SOLD11
TEST_MERGE (7)
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Re: "second computation is a bit off"
How much?
Don't you get a total of 10?
 
Upvote 0
Your output row is Row 10 which is in the middle of the Filter range of row 2:14, that is never going to work.
Also starting the Range at row 2 was not making row 1 the filter row.

Maybe:
VBA Code:
    Range("A1:M" & LastRow).AutoFilter Field:=1, Criteria1:= _
    "=*DAMAGE TO PROPERTY*"

    Range("B" & LastRow + 2) = WorksheetFunction.Subtotal(9, Range("B2:B" & LastRow))
    Range("C" & LastRow + 2) = WorksheetFunction.Subtotal(9, Range("C2:C" & LastRow))
    Range("D" & LastRow + 2) = WorksheetFunction.Subtotal(9, Range("D2:D" & LastRow))
    Range("B1").AutoFilter 'Turn autofilter Off
 
Upvote 0
Solution
Your output row is Row 10 which is in the middle of the Filter range of row 2:14, that is never going to work.
Also starting the Range at row 2 was not making row 1 the filter row.

Maybe:
VBA Code:
    Range("A1:M" & LastRow).AutoFilter Field:=1, Criteria1:= _
    "=*DAMAGE TO PROPERTY*"

    Range("B" & LastRow + 2) = WorksheetFunction.Subtotal(9, Range("B2:B" & LastRow))
    Range("C" & LastRow + 2) = WorksheetFunction.Subtotal(9, Range("C2:C" & LastRow))
    Range("D" & LastRow + 2) = WorksheetFunction.Subtotal(9, Range("D2:D" & LastRow))
    Range("B1").AutoFilter 'Turn autofilter Off

thanks for the info mate....
just notice I accidentally started at A2! well I should start at A1
All is good now, but thanks to all...
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,112
Members
453,021
Latest member
Justyna P

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