Microsoft Office Tutorials and References
In Depth Information
Introducing the Visual Basic Editor
If IsNumeric(MyCell) Then _
Result = “Number” Else _
Result = “Non-Number”
Notice that I indented the last two lines of this statement. Doing this is optional, but it helps to
clarify the fact that these three lines make up a single statement.
After you enter an instruction, the VB Editor performs the following actions to improve readability:
h It inserts spaces between operators. If you enter Ans=1+2 (without any spaces), for
example, VBA converts it to
Ans = 1 + 2
h The VB Editor adjusts the case of the letters for keywords, properties, and methods. If
you enter the following text:
VBA converts it to
user = Application.UserName
h Because variable names are not case sensitive, the VB Editor adjusts the names of all
variables with the same letters so that their case matches the case of letters that you
most recently typed. For example, if you first specify a variable as myvalue (all
lowercase) and then enter the variable as MyValue (mixed case), VBA changes all other
occurrences of the variable to MyValue . An exception to this occurs if you declare the
variable with Dim or a similar statement; in this case, the variable name always appears
as it was declared.
h The VB Editor scans the instruction for syntax errors. If it finds an error, it changes the
color of the line and may display a message describing the problem. You can set various
options for the VB Editor in the Options dialog box (accessible by choosing Tools
Like Excel, the VB Editor has multiple levels of Undo and Redo. Therefore, if you
mistakenly delete an instruction, you can click the Undo button (or press Ctrl+Z)
repeatedly until the instruction returns. After undoing the action, you can choose Edit➜Redo
Delete (or click the Redo Delete toolbar button) to redo previously undone changes.
Using the macro recorder
Another way to get code into a VBA module is to record your actions by using the Excel macro
recorder. No matter how hard you try, you cannot record a Function procedure (the type of
procedure that is used for a custom worksheet function). All recorded macros are Sub procedures.
Search JabSto ::

Custom Search