To create a custom Excel function using Visual Basic for Applications (VBA), follow these steps:
Alt + F11
to open the VBA editor.MultiplyValues
that multiplies two numbers:Function MultiplyValues(num1 As Double, num2 As Double) As Double
MultiplyValues = num1 * num2
End Function
Ctrl + S
or by clicking on the save button in the toolbar.Now, you can use your custom function like any other built-in Excel function. In any cell, simply type =MultiplyValues(A1, B1)
to multiply the values in cells A1 and B1.
Note: When saving an Excel workbook that contains VBA code, make sure to choose the file type "Excel Macro-Enabled Workbook (*.xlsm)" to preserve the VBA code.