VBA Code to get distinct count with muliple criteria

Wafee

Board Regular
Joined
May 27, 2020
Messages
104
Office Version
  1. 2013
Platform
  1. Windows
Can some one help me with a VBA code that gives distinct count of data in in "I" Column of sheet1 (dynamic) after filtering "Temp" and "Tem" in A column and "MX" in E column. I have a code as below which gives distinct count from "I" column but not able to add the filters. Would be great if get a code simpler than this.

Sub Dcount()
Dim Lastrow As Long
Rng As Range
List As Object
Listcount As Long
Lastrow = Cells(Rows.Count,"A").End(xlUp).Row
Set List = Createobject("Scripting.Dictionary)
For Each Rng In Range("I2:I", & Lastrow)
If Not List.Exists(Rng.Value) Then List.Add Rng.Value, Nothing
Next
Listcount = List.Count
Range("M2").Value = ListCount

End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
You're welcome & thanks for the feedback.
 
Upvote 0
You're welcome & thanks for the feedback.
Hi Fluff,

Sorry to come back again but I am new this stuff.from the above code we discussed can we publish the list in to S column. Thanks in advance.
 
Upvote 0
Do you mean you want the list count in S2 instead of M2?
 
Upvote 0
OK, how about
VBA Code:
Range("S2").Resize(List.Count).Value = Application.Transpose(List)
 
Upvote 0
OK, how about
VBA Code:
Range("S2").Resize(List.Count).Value = Application.Transpose(List)
Throwing the on-time error 1004: Apllication or object defined error. Is that something to do with Transpose? I am using 2013 version of ms office.
 
Upvote 0
What is the list count?
ListCount is the count of items in the List.

Below is the code I am using to calculate ListCount as suggested by you earlier.

Dim Listcount As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Set List = CreateObject("Scripting.Dictionary")
With Range("A1:I1")
.AutoFilter 1, "Temp", xlOr, "tem"
.AutoFilter 5, "MX"
End With
For Each Rng In Range("I2:I" & Lastrow).SpecialCells(xlVisible)
List(Rng.Value) = Empty
Next Rng
ActiveSheet.AutoFilterMode = False
Listcount = List.Count
Range("M2").Value = Listcount
 
Upvote 0
What is the actual value in M2 when you get the error?
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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