Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I just started VBA and I\'m just making simple functions, but when I try to call

ID: 3620071 • Letter: I

Question

I just started VBA and I'm just making simple functions, but when I try to call my function in Excel it gives me, "Compile Error: Argument not optional" and highlights my Function and the Cos.

'Functions "sec1" and "tan1" validate the trigonometric relation tan^2(theta) = sec^2(theta) - 1
Function sec1(theta As Double) As Double

sec1 = ((Cos) ^ -1) * (theta ^ 2) - 1

End Function
But, my other trig functions work fine like this one: Function sin1(theta As Double) As Double
sin1 = 1 - Cos(theta) ^ 2
End Function Any help would be appreciated. 'Functions "sec1" and "tan1" validate the trigonometric relation tan^2(theta) = sec^2(theta) - 1 End Function
But, my other trig functions work fine like this one: Function sin1(theta As Double) As Double
sin1 = 1 - Cos(theta) ^ 2
Function sin1(theta As Double) As Double
sin1 = 1 - Cos(theta) ^ 2
End Function Any help would be appreciated.

Explanation / Answer

The disadvantage of Excel's 'user defined functions' is that they can only return a single value, and the function cannot alter the properties of the worksheet. Arguments you pass to the VBA functions you define are passed 'by value'.