Office tutorials

# Functions in VBA Excel

## Introduction to functions in Excel VBA

You have already come to the chapter about functions – Congratulations, keep it up !!! In VBA we have a number of useful functions. It is through them that our programs will work in the right way. With their help, we will perform mathematical activities, manipulate text data and dates. We reference the function in VBA in a standard way by entering the function name, arguments and parentheses: FULL – TERMINATION (arguments) . The VBA functions can be divided into the following groups:

• Character functions
• Mathematical functions
• Date and time functions
• Logic functions
• Excel Sheet functions – sheet functions
• User functions
• others

Using the Excel Spreadsheet function, you can refer to any function used in the Worksheet. The function names are displayed in English. We refer to the Excel Spreadsheet function by entering the Application.WorksheetFunction. FUNCTION_name statement.

The VBA functions, like in the datasheet, can be combined with each other using the following syntax: function_2 (function_1 (arguments of function_1)). So the result of function_1 is also an argument to function_2. They are so-called nested functions . We will learn all the features we need in the next chapters of our course.

## An example of using a VBA function

For starters, let’s try to write a short macro using InputBox and MsgBox , which will extract the square root of the value we enter. We use the Sqr () function for this purpose .

In the next step, let’s round our value to 2 decimal places using the Round () function . The brackets of both functions must of course be closed:

In the next example, we will use the character function. As in the previous example, we use the InputBox and MsgBox elements. Our goal is to rework the text data entered into the uppercase text. We will use the Ucase () function for this purpose .

In the next chapters of the course we will learn in turn all the categories of functions we have learned in Excel VBA.

## Tasks (You can save the result in a comment)

1. Process the function from point 2. Make the result displayed in cell B2 of Sheet3.

More examples of Excel VBA basics can be found in the Excel VBA Tutorial section and  Examples in VBA  section. If you have any questions about this chapter, you can post them on the forum without logging in.

### 1 comment

1. • li on June 24, 2018 at 8:58 am

Do you have any video of that? I’d care to