无法获取工作表函数类的countif属性

时间:2019-06-04 11:23:22

标签: excel vba

我正在尝试使用countIf检查单元格值是否在另一个范围内,但是出现上面的错误,我试图loop though the range来寻找值,但没有成功

我还试图在countIf之前转换列的两种格式

    With col_member_id
        .NumberFormat = "General"
        .Value = .Value
    End With

    With col_remarks
        .NumberFormat = "General"
        .Value = .Value
    End With

这是我的代码

Sub CheckValue()

    Dim tbl_data As ListObject, _
        tbl_member As ListObject, _
        col_member_id As Range, _
        col_id As Range, _
        col_done_by As Range, _
        col_remarks As Range, _
        col_type As Range, _
        col_amount As Range, _
        col_payment As Range

    Set tbl_data = ActiveWorkbook.Worksheets("Sheet1").ListObjects("Data")
    tbl_data.ListColumns.Add.Name = "Payment"

    Set tbl_member = ActiveWorkbook.Worksheets("Member Names").ListObjects("tbl_member")
    Set col_member_id = tbl_member.ListColumns("MEMBER ID").Range
    Set col_id = tbl_data.ListColumns("IDs").Range
    Set col_done_by = tbl_data.ListColumns("Done By").Range
    Set col_remarks = tbl_data.ListColumns("Remarks").Range
    Set col_type = tbl_data.ListColumns("Type").Range
    Set col_amount = tbl_data.ListColumns("Amount").Range
    Set col_payment = tbl_data.ListColumns("Payment").Range

    For i = 1 To col_id.Cells.Count + 1

        If (Cells(i, col_done_by.Column).Value = "gg1") And _
            (Cells(i, col_amount.Column).Value > 0) And _
            (Application.WorksheetFunction.CountIf(col_member_id, Cells(i, col_remarks.Column).Value) > 0) And _
            ((Cells(i, col_type.Column).Value = "ww") Or (Cells(i, col_type.Column).Value = "tt")) Then
            Cells(i, col_payment.Column).Value = "gg1 done"
        End If

    Next i

End Sub

0 个答案:

没有答案