我试图在名为First Name的B列中做一个countif,其中包含不同的名称,但结果返回0.
这是我的代码:
公共子计数() Dim lastcell As String
Range("B2").Select
Selection.End(xlDown).Select
lastcell = ActiveCell.Address
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = "=countif(B2:" + lastcell + ", John)"
End Sub
如果我检查活动单元格中写的公式是:
= COUNTIF(B2:$ B $ 16,John)
请帮忙。
我尝试更改
中的行ActiveCell.Value =" = countif(B2:" + lastcell +",John)"
到
ActiveCell.Value =" = countif(B2:" + lastcell +"," John")"仍然没有工作。
答案 0 :(得分:1)
Public Sub counting()
With Range("B2").End(xlDown)
.Offset(1, 0).Formula = "=COUNTIF(B2:" & .Address(False, False) & ", ""John"")"
End with
End Sub
答案 1 :(得分:0)
尝试,
ActiveCell.formula = "=countif(B2:" & lastcell & chr(44) & chr(34) &"John" &chr(34) & ")"