Make VBA code call a worksheet function

Started by nandagopal, Nov 03, 2008, 05:03 PM

Previous topic - Next topic

nandagopal

The following VBA function isin a standard code module. It uses Application.WorksheetFunction to call the StdDev worksheet function.


Public Function MyStdev(ByVal stdev_range As Range)
    ' Call the worksheet function.
    MyStdev = _
        Application.WorksheetFunction.StDev(stdev_range)
End Function


The following cell content calls the VBA function. Another cell on the worksheet calls StDev directly so you can compare the results.


=mystdev(B2:B6)