VBA Count Unique Values in Column Based on Criteria from Another Column

lamarh755

New Member
Joined
Jan 28, 2020
Messages
44
Office Version
  1. 2013
I have a column ("AM") in Excel that lists LPN values. There can be duplicate LPNs in this column.
I have another column ("DR") that contains numeric values.
I would like to count the number of LPNs in Range("AM8:AM" & lastRow) in which the values in Range("DR8:DR" & lastRow) are ">=3.00"
I would like to count each LPN only once, so no duplicate values in Range("AM8:AM & lastRow)
In this case, lastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row

I would like the count result to be displayed in Range("N5")

Any assistance would be greatly appreciated.
 
Try:

VBA Code:
Sub test1()
Dim dic As Object, MyData As Variant, i As Long

    Set dic = CreateObject("Scripting.Dictionary")
    MyData = Range("AM8:DR" & Cells(Rows.Count, "AM").End(xlUp).Row)
    
    For i = 1 To UBound(MyData)
        If MyData(i, UBound(MyData, 2)) >= 3 Then dic(MyData(i, 1)) = 1
    Next i
    
    Range("N5").Value = dic.Count
End Sub
 
Upvote 0
Solution
Try:

VBA Code:
Sub test1()
Dim dic As Object, MyData As Variant, i As Long

    Set dic = CreateObject("Scripting.Dictionary")
    MyData = Range("AM8:DR" & Cells(Rows.Count, "AM").End(xlUp).Row)
   
    For i = 1 To UBound(MyData)
        If MyData(i, UBound(MyData, 2)) >= 3 Then dic(MyData(i, 1)) = 1
    Next i
   
    Range("N5").Value = dic.Count
End Sub
This worked! Thank you!!!
 
Upvote 0
This worked! Thank you!!!
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

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