How to create and call Excel VBA custom procedure or subroutine?

Since it is a language that Microsoft Office contains to perform certain tasks, it establishes a number of terms necessary to create a procedure.

If your concern is not being able to understand the methods among which you can code using macros from Excel. Here you will find the simplest explanation.

What is a procedure and how can I create it?

What is determined in Excel as a procedure is nothing more than the smallest unit of code executed in Visual Basic.




They are easy to recognize as they are always at the beginning and end of all macro coding that is performed within the program to perform a task.

The types of procedures are classified as " Bottom "," Function " is " Property "At the beginning, and are closed with the term" end "Before them.

You can create a subroutine or a custom procedure using the options " Sheet " is " Forms ". Using the objects encoded by " ThisWorkbook "Or" UseForms ".

 

Create a module in the Visual Basic Editor to create a procedure or subroutine

In case you don't know how to add a module to projects within VBA, you just need to access the tab " Developer "And you will see the button" Visual Basic ".

How to create and call Excel VBA custom procedure or subroutine?

A new window will open in front of your screen which is considered as the editor, which has the icon in its menu " Inserisci "Where you will find the option" Module ".


Automatically in the small vertical box on the left you will see how a folder is created where the new module just created will appear.



This way you just need to click on the box on the right to start writing the Visual Basic language to start creating the activity you want to use.

Learn how to create a subroutine or custom procedure with Visual Basic

In the beginning, you will gradually learn the different functions that can be performed through the modules to give energy to the contents of the spreadsheet.

For now, you'll start with the smallest, that is set the start and the main elements of the activity you want to perform.

Create a secondary procedure

In VBA, there are two ways to establish the start of a procedure. Either manually in the window or by clicking through the menu " Inserisci ".

To enter the procedure manually, you need to access the window of the module you created, where you will write the word " Sub " and then you will have to write the name of the macro that you will perform.

How to create and call Excel VBA custom procedure or subroutine?



 

Press the button " Submit "To allow Visual Basic to automatically add the parentheses and the statement" End Sub "Below it.

Between the two lines you need to write the code of the activity you want to run and after you have finished save it and run it.

Create a function procedure

Like the previous one, it can be created through an object that allows you to write and execute code.


Then start by creating a " New module "And in the code window shown on the right write" Function ”Followed by the name you will give the function.

When you press " Submit ", VBA will add the parentheses and the statement to terminate the function known as" End Function ".

Now you just have to write the code between the two lines of the activity you want to do in your Excel sheet, save it and execute the function.

If you will be working with Visual Basic, it is also important that you know how to handle the different error handling that Visual Basic can present to you.

Expand your knowledge of using VBA by using and creating a FOR-NEXT loop.

add a comment of How to create and call Excel VBA custom procedure or subroutine?
Comment sent successfully! We will review it in the next few hours.