We will do a basic review of exponential forms in VBA.
.000123 = 1.23E-4
12536 = 1.2536E4
12.345 = 1.2345E1
Log in VBA returns the natural logarithm of a number. (Notice that this is different from the Worksheet, where Log signifies Log base 10.) To get the base 10 logarithm we must divide the natural log by 2.303.
Log (15.3) = 2.727853 (In VBA Log() returns the natural logarithm.)
2.727853 / 2.303 = 1.184478 (This is the base 10 logarithm of 15.3.)
Unfortunately there is no VBA user defined function for pi. This means you must input a value manually. You must supply the angle in radians for all VBA trigonometric functions.
Radians = Degrees * Pi/180 Where Pi = 3.1416
Cosine of 30 degrees = Cos(.5236) in radians = .866
Here are some examples of how to change the format of numbers in VBA.
Sub myFormat()
MsgBox Format(222.6, "Standard") '222.60
MsgBox Format(0.771, "Percent") '77.10%
MsgBox Format(1437.5, "Currency") '$1,437.50
MsgBox Format(126345, "Scientific") '1.26E+05
End Sub
The Round function rounds a number to a specified number of digits in VBA.
Round(3.555, 1) = 3.6
Round(3.555) = 4
Round(.0003334, 2) = 0
Round(.0003334, 4) = .0003
Round(342.01) = 342
Table of Contents
Ch1-Introduction
Ch2-Loops
Ch3-If Statements
Ch4-Functions
Ch5-Subs & Functions
Ch6-Read & Write
Ch7-Operators
Ch8-Built-in Functions
Ch9-Built-in Examples
Ch10-Debugging
Ch11-Running Subs
Ch12-Sample Programs
Ch13-WS Formulas
Ch14-Questions