PDA

View Full Version : User Defined Function - Mtwo = 2X



clarksonneo
04-14-2011, 06:35 AM
Hi,

I want to create an User Defined Function.

The function will mutliply a number by 2.

For example,
suppose x is 10 and the function name is Mtwo,
then = Mtwo(10) will give 20.

However, I don't need a reference in ( ).
For example, I don't need
Mtwo(A2) = 20, where the cell A2 has the number "20".

Thanks

Kenneth Hobs
04-14-2011, 08:09 AM
If A2=20 then =Mtwo(A2)=40.

You can use the function with a number as the input or a cell reference. You can change Double to Long if you never have decimal values. In a Module paste:
Function Mtwo(aNumber As Double) As Double
Mtwo = 2 * aNumber
End Function