Set autofilter subtotal to a double

powerdink

New Member
Joined
Feb 16, 2011
Messages
21
Hello,

I'm attempting to take a range of data and filter the fourth column by an array of specific values. Then once filtered, subtotal the visible cells in the 7th column and set a double variable as that subtotal value.

Whatever I'm doing isn't working because the variable when inserted into another worksheet keeps coming in as "0", which I know is not correct. Here is the part of code I think is incorrect. all ranges and variables have already been dim'd.

Code:
    Set rng1 = ActiveWorkbook.ActiveSheet.Range("A1").CurrentRegion
    
    With rng1
        .AutoFilter
        .AutoFilter field:=4, _
        Criteria1:=Array("601", "602", "641", "642", "643"), Operator:=xlFilterValues
        Set rng2 = .Offset(1, 7).Resize(.Rows.Count - 1, 1).SpecialCells(xlVisible)
        dblThroughPut = Application.WorksheetFunction.Subtotal(109, rng2)
    End With
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try replacing rng2 with rng1 in that Subtotal function (the whole point of it is that it ignores hidden rows after all. :))
 
Upvote 0
Thanks Rory,
I tried swapping rng2 with rng1 in my subtotal function and I get a number, but it is definately not correct. My "grand Total" of all cells in the 7th column is around 1,200,000 so any autofilter subtotal should essentially be less than that. With rng1 in the subtotal function, my variable value is being set in the 700,000,000 range.

Any other ideas?
 
Upvote 0
Sorry - really wasn't paying enough attention - you want rng1.columns(8)
 
Upvote 0

Forum statistics

Threads
1,214,804
Messages
6,121,652
Members
449,045
Latest member
Marcus05

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