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
 
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
I would suggest making the two small changes shown in red below to Fluffs original code (then there is no need to check if the filter produced any names or not) and use .Count - 1 in your report (or set up a new variable and set its value to .Count - 1)

How about
Code:
Sub Danny54()
   Dim Cl As Range
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("A[COLOR="#FF0000"][B][SIZE=4]3[/SIZE][/B][/COLOR]", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlVisible)
         .Item(Cl.Value) = Empty
      Next Cl
      MsgBox .Count [COLOR="#FF0000"][B][SIZE=4]- 1[/SIZE][/B][/COLOR]
   End With
End Sub
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,214,405
Messages
6,119,323
Members
448,887
Latest member
AirOliver

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