Unique count on filtered data

Danny54

Active Member
Joined
Jul 3, 2019
Messages
295
Office Version
  1. 365
Platform
  1. Windows
ws.Range("A3:H3000").Select
Selection.AutoFilter
wb.ActiveSheet.Range("$A$3:$H$275").AutoFilter Field:=5, Criteria1:= _
"=*Update*", Operator:=xlAnd






The following is the output after running the filter above




a b c d e
1
2
3 Name Title
5 D001 Update
6 D001 Update
7 D001 Update
10 BMOCADAPP01M001 Update




How can I get a unique count of col a? Everything I try gives me a count of the unfiltered stuff




Dim Server_Name As Range
Dim List As Object
Dim erow As Integer

Set List = CreateObject("Scripting.Dictionary")
erow = ActiveSheet.Cells(1, 1).CurrentRegion.Rows.Count + 1
erow = ActiveSheet.Cells(1, 1).Special

For Each Server_Name In ws.Range("A4:A" & erow)
If Not List.Exists(Server_Name.Value) Then List.Add Server_Name.Value, Nothing
Next

MsgBox List.Count


Thanks
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
How about
Code:
Sub Danny54()
   Dim Cl As Range
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("A4", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlVisible)
         .Item(Cl.Value) = Empty
      Next Cl
      MsgBox .Count
   End With
End Sub
 
Upvote 0
sometimes you can't see the forest for the trees.

that worked.

Thanks So Much!
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
Just noticed that when my filter runs and returns no actual data the .Count shows 1 found.
any ideas why?
 
Upvote 0
If there are no visible cells, it will be counting the header in row 3
 
Upvote 0
It looks like this code counts the Name Labels as a field being selected? Any way of ignoring the Name Labels?

For Each Cl In Range("A4", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlVisible)
.Item(Cl.Value) = Empty
Next Cl
 
Upvote 0
Yep, thats exactly what its doing. My goal would be to only count actual data rows, so effectively the .Count field would be 0
 
Upvote 0
Simply add this line at the beginning of the code
Code:
   If Range("A" & Rows.Count).End(xlUp).Row = 3 Then Exit Sub
 
Upvote 0
Solution
would there be a simple way to set the .count field to 0 when this condition occurs? Im using the .Count field in a report
 
Upvote 0

Forum statistics

Threads
1,223,702
Messages
6,173,967
Members
452,539
Latest member
delvey

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