MS-Excel / Functions and Formula

# Using VBA's Mathematical Functions

VBA provides a solid suite of functions for standard mathematical operations. Table below lists these functions with examples.

VBA's mathematical functions
 Abs(number) The absolute value of number - the unsigned magnitude of the number. Abs(-100) returns 100. Atn(number) The arctangent of number in radians. Atn(dblMyAngle) Cos(number) The cosine of angle number. Cos(dblMyAngle) Exp(number) e, the base of natural logarithms, raised to the power of number. Exp(5) returns 148.413159102577. Fix(number) The integer portion of number (without rounding). If number is negative, returns the negative number greater than or equal to number. Fix(3.14159) returns 3. Fix(-3.14159) returns -3. Int(number) The integer portion of number (again, without rounding). If number is negative, returns the negative number less than or equal to number. Int(3.14159) returns 3. Int(-3.14159) returns -4 . Log(number) The natural logarithm of number. Log(dblMyAngle) Rnd([number]) A random number (with no argument) or a number based on the given initial seed. Rnd(1) returns a random number. Sgn(number) -1 if number is negative, 0 if number is 0, 1 if number is positive. Sgn(7) returns 1. Sgn(-7) returns -1. Sgn(0) returns 0. Sin(number) The sine of the angle specified by number (measured in radians). Sin(dblMyAngle) Sqr(number) The square root of number. If number is negative, VBA gives a runtime error. Sqr(9) returns 3. Tan(number) The tangent of the angle specified by number (measured in radians). Tan(dblMyAngle)