计算列的唯一值,其中2列符合特定条件

时间:2013-10-21 19:12:56

标签: excel

计算列的唯一值,其中2列符合特定条件。假设列A是重复的索赔号列表,因为每个索赔在多个月内有多个帐单(月份是列B,位置是列C),每行代表一个帐单。我需要能够使用month = 3和location =“Chicago”

的标准来计算唯一的索赔号
-Claim #   Month   Location
-1234      3       Chicago
-1234      3       Chicago
-1234      3       Chicago
-1234      3       Chicago
-3215      3       Chicago
-3215      3       Chicago
-3215      3       Chicago
-1334      4       Chicago
-1334      5       Chicago
-1235      3       Philadelphia

这里的答案应该是2

1 个答案:

答案 0 :(得分:0)

尝试这个小宏:

Sub dural()
    Dim c As Collection
    Set c = New Collection
    Dim N As Long, i As Long
    N = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To N
        If Cells(i, 2).Value = 3 And Cells(i, 3).Value = "Chicago" Then
            On Error Resume Next
            c.Add Cells(i, 1), CStr(Cells(i, 1))
        End If
    Next
    MsgBox c.Count
End Sub