Checking the logical condition

Checking the logical condition is done using the If-Then-Else structure. It starts with the command If, followed by a logical condition that is formed in the same way as in Excel. Next follows the command Then, aftwer which goes the part of the code to be executed if the condition is met. Optionally, Else command can be specified, followed by a part of the code that is executed if the condition is not met. The structure ends with an End If command, which is not necessary if there’s only one command after Then.

MsgBox and InputBox

MsgBox is an internal VBA procedure (method) used to display content within a dialog window that appears on the screen. It can be used to display the operand that we have directly transmitted or the values ​​of the variables that are calculated within the subroutine. InputBox is a function that we use to enter values ​​that we will later use to calculate the expression.

Value assignment

In previous posts you have seen how variable values are assigned and in this text I will look at Variant data type, basic arithmetic as well as some other operations that we can use to calculate desired expressions. I think it will be especially helpful for you to find out how to set the fixed length strings, and how to merge more of them into one.

Custom functions

In the preceding text we talked about procedures and now we will mention functions. Functions are known as subroutines that calculate and return certain values. We can call them from other programs and it is possible to create custom functions that we will later use in worksheets. This is useful when Excel does not have the specific features you need to perform everyday work.

First VBA program

When you create an Excel macro, it automatically defines a new subroutine, which is actually a program that runs after the specified action. You can also create subroutines independently which could be called from other programs, or run in the manner described below. This text will show how a simple code is written and how it is then linked to the objects that are used to launch it.