This article is part of my series: Excel VBA & Macros – A Step by Step Complete Guide.
In this example, I am going to write a VBA function that will calculate the area of a rectangle. We know the area of a rectangle= Length ☓ Width.
This is a very simple function. Below shows the code:
Function Area(Length, Width) 'Finding out the Area of the Rectangle. Area = Length * Width MsgBox "The Area of your Rectangle is: " & Area End Function
This function takes two arguments(Length and Width) from the user and shows the area of the rectangle in a message box.