I used the following automatic functions to realize the requirements of the post. My program code is as follows (the code is in the module):
After entering the above program, you can calculate in the table. Here is an example of my calculation of 10 and 20:
The program text code is as follows:
Option explicit
Function User-defined function 1(n) is Double.
Size r#, i%
if VarType(n)& lt; & gt vbDouble then.
Custom function1= "parameter"&; N & "Not an integer!"
other
r = 1
For i = 2 to n-1
If n Mod i = 0, then
If the prime number judges (i), then r = r * (1- 1/i).
If ... it will be over.
Next, I
Custom function 1 = r
If ... it will be over.
End function
The function prime number judgment (n) is Boolean.
Dimension i%
Prime number judgment = false
For i = 2 to n-1
If n Mod i = 0, the function is exited.
Next, I
Prime number judgment = true
End function