11.08.2013 Views

Excel's Formula - sisman

Excel's Formula - sisman

Excel's Formula - sisman

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

610<br />

Part VI: Developing Custom Worksheet Functions<br />

If IsNumeric(MyCell) Then _<br />

Result = “Number” Else _<br />

Result = “Non-Number”<br />

Notice that I indented the last two lines of this statement. Doing this is optional, but it helps to<br />

clarify the fact that these three lines make up a single statement.<br />

After you enter an instruction, the VB Editor performs the following actions to improve readability:<br />

It inserts spaces between operators. If you enter Ans=1+2 (without any spaces), for<br />

example, VBA converts it to<br />

Ans = 1 + 2<br />

The VB Editor adjusts the case of the letters for keywords, properties, and methods. If<br />

you enter the following text:<br />

user=application.username<br />

VBA converts it to<br />

user = Application.UserName<br />

Because variable names are not case sensitive, the VB Editor adjusts the names of all<br />

variables with the same letters so that their case matches the case of letters that you<br />

most recently typed. For example, if you first specify a variable as myvalue (all lowercase)<br />

and then enter the variable as MyValue (mixed case), VBA changes all other<br />

occurrences of the variable to MyValue. An exception to this occurs if you declare the<br />

variable with Dim or a similar statement; in this case, the variable name always appears<br />

as it was declared.<br />

The VB Editor scans the instruction for syntax errors. If it finds an error, it changes the<br />

color of the line and may display a message describing the problem. You can set various<br />

options for the VB Editor in the Options dialog box (accessible by choosing Tools➜<br />

Options).<br />

Like Excel, the VB Editor has multiple levels of Undo and Redo. Therefore, if you mistakenly<br />

delete an instruction, you can click the Undo button (or press Ctrl+Z) repeatedly<br />

until the instruction returns. After undoing the action, you can choose Edit➜Redo<br />

Delete (or click the Redo Delete toolbar button) to redo previously undone changes.<br />

Using the macro recorder<br />

Another way to get code into a VBA module is to record your actions by using the Excel macro<br />

recorder. No matter how hard you try, you cannot record a Function procedure (the type of<br />

procedure that is used for a custom worksheet function). All recorded macros are Sub procedures.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!