Failure to count number of cells in filtered table

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,570
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Rich (BB code):
       With ws_cd1
            cnt_date = Application.WorksheetFunction.CountIf(.Columns(1), n_date)
            cnt_rows = Application.WorksheetFunction.Count(.Columns(1))
            rte = cnt_rows - cnt_date
            .Unprotect
            .Range("AP3").Value = "CORE DATA   " & Chr(208)
            .Range("AP3").Characters(Len(.Range("AP3").Value), 1).Font.Name = "Webdings"
            .Range("A1").AutoFilter Field:=1, Criteria1:="<>n_date"
            test = Application.WorksheetFunction.Subtotal(2, .columns(1)))
        End With

This code filters worksheet ws_cd1 so that only rows not equal to n_date in column A are visible. The line in red (Googled) is supposed to count the number of rows in the filtered list by means of counting how many numbers are visible in column A. This number should be equal to the value calculated for rte which is the number of rows in column A minus the number of instances of n_date (which would be filtered out). cnt_date = 28; cnt_rows = 5575

The worksheet does filter, however, the value for test = 5575, which would be incorrect. test should equal 5547 (5575-28).
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I guess n_date is a variable.
Then try like this:

Rich (BB code):
.Range("A1").AutoFilter Field:=1, Criteria1:="<>" & n_date
 
Upvote 0

Forum statistics

Threads
1,223,950
Messages
6,175,582
Members
452,653
Latest member
craigje92

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