Reputation: 5904
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. 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? Thanks
EDIT: Using 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))"
Upvotes: 0
Views: 2399
Reputation: 34075
You should us US style separators:
Range("E6").Formula = "=SUM(IF(FREQUENCY(MATCH(A2:A96,A2:A96,0),MATCH(A2:A96,A2:A96,0))>0,1))"
Upvotes: 2
Reputation: 19737
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))"
Upvotes: 0