View Single Post
  #5   Report Post  
kalkap kalkap is offline
Junior Member
 
Posts: 4
Default

Quote:
Originally Posted by Ben McClave View Post
Hello,

This function worked for me with some test data. To use it, paste the code below to a new module and then enter the formula on a cell in your worksheet with this format:

"=CountFromColumn(CountRange, CriteriaRange,Criteria1, Criteria2)"

For example, if your components were in range A1:A10 and your outage identifier was in range B1:B10, you would write:

"=CountFromColumn(A1:A10, B1:B10, "Refurbish Actuator", "Diagnostic Testing")"

Here is the code (adapted from a post at http://www.mrexcel.com/forum/excel-q...s-range.html):

Function CountFromColumn(CountRange As Range, CriteriaRange As Range, _
Criteria1 As String, Criteria2 As String)
Dim oChecked As Object
Dim lCount As Long
Dim rCell As Range

Set oChecked = CreateObject("scripting.dictionary")
lCount = 0

With oChecked
.comparemode = 1
For Each rCell In CountRange
If Not .exists(rCell.Value) Then
.Add rCell.Value, Nothing
If _
((WorksheetFunction.CountIfs(CountRange, rCell, _
CriteriaRange, Criteria1) 0) And _
(WorksheetFunction.CountIfs(CountRange, rCell, _
CriteriaRange, Criteria2) 0)) Then
lCount = lCount + 1
End If
End If
Next
End With
CountFromColumn = lCount
End Function
I feel like this is on the right track but I can't seem to get it to work. I tried everything in my original spreadsheet and messed around with it a bit but can't seem to get anything other than Zeros. Could be just me as I've only ever messed with functions in Excel and not VBA. I made a dummy file with the pertinent information and hoping you might have some more insight for me?

Thanks again for the help.
Attached Files
File Type: zip Test Spreadsheet.zip (51.8 KB, 61 views)