Welcome to Excel Jet Consult blog post. In this blog post, we will learn how to create a custom user defined function in Excel VBA that will require three arguments
We will open the VBA with ALT + F11 and insert a module
In the code window, execute the lines of code as seen in the caption below
In the caption above, we provided SpecialTotal as the name of our custom function. The Sub_Total, Discount and Shipping_Cost are named ranges in our data set and we used Integer data type
In the second line of code, we also specify the name of our custom function and set it to equal Sub_Total – Discount + Shipping_Cost
Next, we will close the VBA Editor and use the function
In the caption above, we can see the function created
In the caption above, we want to use the SpecialTotal custom function to calculate the Total which is Sub_Total – Discount + Shipping_Cost
In cell U4, click on Insert Function and search for SpecialTotal
Reference cell Q2, S2, T2. We can see from caption below that the expect output is ₦7,143
Click OK and apply auto-fill
It worked fine
Absolutely fantastic
Thanks for this insignful post. Someone like me who is starting out learning Visual Basic will benefit from your post.