countif在macros中给出0个结果
我正在尝试在名为First Name的B列中使用不同名称的countif,但结果返回0。
这是我的代码:
Public Sub counting()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,约翰)
请帮忙。
我试图改变线路
ActiveCell.Value =“= countif(B2:”+ lastcell +“,John)”
至
ActiveCell.Value =“= countif(B2:”+ lastcell +“,”John“)”仍然不工作。
Public Sub counting() With Range("B2").End(xlDown) .Offset(1, 0).Formula = "=COUNTIF(B2:" & .Address(False, False) & ", ""John"")" End with End Sub
尝试,
ActiveCell.formula = "=countif(B2:" & lastcell & chr(44) & chr(34) &"John" &chr(34) & ")"