11.08.2013 Views

Excel's Formula - sisman

Excel's Formula - sisman

Excel's Formula - sisman

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

628<br />

Part VI: Developing Custom Worksheet Functions<br />

Figure 23-7: Using the VB Editor Immediate window to display results while a function is running.<br />

Calling the function from a Sub procedure<br />

Another way to test a Function procedure is to call the function from a Sub procedure. To do<br />

this, simply add a temporary Sub procedure to the module and insert a statement that calls your<br />

function. This is particularly useful because runtime errors display as they occur.<br />

The following Function procedure contains a runtime error. As I noted previously, the runtime<br />

errors don’t display when testing a function by using a worksheet formula. Rather, the function<br />

simply returns an error (#VALUE!).<br />

Function REVERSETEXT(text) As String<br />

‘ Returns its argument, reversed<br />

Dim TextLen As Long, i As Long<br />

TextLen = Len(text)<br />

For i = TextLen To 1 Step -1<br />

REVERSETEXT = REVERSETEXT And Mid(text, i, 1)<br />

Next i<br />

End Function

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

Saved successfully!

Ooh no, something went wrong!