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
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,414
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Try replacing rng2 with rng1 in that Subtotal function (the whole point of it is that it ignores hidden rows after all. :))
 

powerdink

New Member
Joined
Feb 16, 2011
Messages
21
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?
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,414
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Sorry - really wasn't paying enough attention - you want rng1.columns(8)
 

Watch MrExcel Video

Forum statistics

Threads
1,126,949
Messages
5,621,781
Members
415,856
Latest member
jimb2k

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
Top