VBA: Use Worksheet Functions in a Macro

Automate Excel

VBA: Use Worksheet Functions in a Macro

The ability to use Excel’s built in functions when programming with VBA can be a great time saver.

In this example I’ll use the Combin function. Remember Combin is used to return the maximum combinations when given the number in the pool and the number drawn. The following code demonstrates a worksheet function used in VBA to find the combinations when given a pool of 42 with a draw of 6:

Sub UseFunction()

MsgBox Application.WorksheetFunction.Combin(42, 6)

End Sub

Running this macro tells us in a message box the result of the Combin function, and we’ve successfully used a worksheet function with VBA.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.