• Kalpesh Agrawal

Create own functions in VBA

You can see many functions like, “SUM”, “MATCH”, and “SHEET” in Excel.

You can create your own functions using VBA code.

Let’s see an example…

This is the simple code.

You just have to type the code in Editor Pane do not need to run.

After typing the code, go to the Excel sheet.

Try to write the function in the Excel sheet as below…

You can see that the code is working properly and Excel is showing the exact option as we entered in the code.

Let’s do some calculations using this function…

Some complex multiplication…

Let’s see one more example...

You might think that why the code is showing an error, but you can see that the pop-up message informing that “A value in the formula is of the wrong data type”.

The data types integer contains the value that has a range between “-32,768 to 32,767”.

To get the result, we have to change the data type from Integer to Long, as the data type Long used for the range of values between “-2,147,483,648 to 2,147,483,647”.


Recent Posts

See All