Calling A worksheet function from Excel VBA


Back to Index | Table of Contents

 

In Visual Basic, the Microsoft Excel worksheet functions are available through the WorksheetFunction object. The following procedure uses the Max worksheet function to determine the largest value in a range of cells´

 

Sub FunctionDemo()
    
    Set myRange = Worksheets("Sheet1").Range("A1:B10")
    ans = Application.WorksheetFunction.Max(myRange)
    MsgBox ans
 
End Sub
 

The range A1:B10 on Sheet1 is Set as myRange. Another variable, ans, is assigned the result of applying the Max function to myRange which then show up in a message box when you execute the procedure.

 

   
WidgetBucks - Trend Watch - WidgetBucks.com

HOME