Microsoft Excel Training Videos

Calling a Worksheet Function from a macro in Microsoft Excel


In Visual Basic, the Microsoft Excel worksheet functions are available through the WorksheetFunction object.
The following Sub procedure or macro uses the Min worksheet function to determine the smallest value in a range of cells. First, the variable myRange is declared as a Range object, and then it’s set to range C3:C8 on Sheet1. Another variable, answer, is assigned the result of applying the Min function to myRange. Finally, the value of answer is displayed in a message box. The training video below describes the complete process
Sub UseFunction()
Dim myRange As Range
Set myRange = Worksheets("Sheet1").Range("C3:C8")
answer = Application.WorksheetFunction.Min(myRange)
MsgBox answer
End Sub




Microsoft Excel Training Videos