[英]Run-time error '1004' using a formula in a macro vba
I'm trying to insert a formula in a macro vba and write the output in a cell but i get a run-time error.. I'm not a vba developer so i can't understand what is wrong. 我试图在宏vba中插入一个公式并在单元格中写入输出,但我得到一个运行时错误..我不是一个vba开发人员所以我无法理解什么是错的。 I write only some simple macros.. This is what i wrote so far:
我只写了一些简单的宏..这是我到目前为止写的:
Sub count()
Range("E6").Formula = "=SUM(IF(FREQUENCY(MATCH(A2:A96;A2:A96;0);MATCH(A2:A96;A2:A96;0))>0;1))"
End Sub
I expect that in the E6
cell will get the output, using only the formula i get 51, but when i run the macro i get the error.. Any help? 我希望在
E6
单元格中获得输出,只使用公式我得到51,但是当我运行宏我得到错误..任何帮助? Thanks 谢谢
EDIT: Using InputBox 编辑:使用InputBox
Dim myRange As Range
Set myRange = Application.InputBox(Prompt:= _
"Select a Range", _
Title:="InputBox Method", Type:=8)
Range("E6").Formula = "=SUM(IF(FREQUENCY(MATCH(A2:A96,A2:A96,0),MATCH(A2:A96,A2:A96,0))>0,1))"
您应该使用我们的美式分隔符:
Range("E6").Formula = "=SUM(IF(FREQUENCY(MATCH(A2:A96,A2:A96,0),MATCH(A2:A96,A2:A96,0))>0,1))"
As commented, this should work: 评论说,这应该工作:
Range("E6").Formula = _
"=SUM(IF(FREQUENCY(MATCH(A2:A96,A2:A96,0),MATCH(A2:A96,A2:A96,0))>0,1))"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.