Hello everyone,
I have an issue with a Function I am trying to create. The function’s target is to bring as a result whether a number is prime or not.
The code I have prepared is the following:
When I try to run the code, a compile error appears, saying “Wrong number of arguments or invalid property assignment”.
It indicates the “Sqr”
I am entirely new to VBA, and I would appreciate your help in this matter.
I have an issue with a Function I am trying to create. The function’s target is to bring as a result whether a number is prime or not.
The code I have prepared is the following:
Code:
[[B]Function prime[/B](n As Integer) As Boolean
Dim Flag As Boolean, l As Integer, i As Integer
l = WorksheetFunction.RoundDown(Sqr(n, 0))
Flag = True
For i = 2 To l
If n Mod i = 0 Then
Flag = False
End If
Next i
If Flag = True Then
prime = False
Else
prime = True
End If
'Place your code here
End Function]
It indicates the “Sqr”
I am entirely new to VBA, and I would appreciate your help in this matter.
Last edited by a moderator: