Excel中的VBA代码,参数不可选,CountIf错误

问题描述 投票:1回答:1

我创建了一个代码来查找Sheet27中A列中数字1的实例,但它不断给出错误“参数不是可选的”并突出显示代码的CountIf部分。我希望此信息显示为msgbox。

Private Sub CommandButton1_Click()

    Dim instances As Long
    instances = WorksheetFunction.CountIf(Sheets("Sheet27")(Columns("A:A"), "1"))

    MsgBox "We Found " & instances & " instances of ", vbInformation, "Alert"

End Sub
excel vba excel-vba countif
1个回答
1
投票

尝试...

instances = WorksheetFunction.CountIf(Sheets("Sheet27").Columns("A:A"), "1")
© www.soinside.com 2019 - 2024. All rights reserved.