For-Next loop

Loops are structures that are used if we want to repeatedly execute given program code. The easiest to understand and probably most often used is the For-Next Loop. It is used when we know exactly how many times we want to repeat a particular action. First, the initial and the end value are set; we can also set the optional Step value for which counter is being incremented. Further we enter the programme code and in the end Next statement and a counter name.

Multiway branching

Sometimes it is necessary to examine the condition so that, depending on the result value, program offers multiple alternative actions. In this case, the Select-Case structure for multiway branching is used. It works by sending a parameter to it and, depending on its value, different parts of the program are executed. If the parameter value differs from all the alternatives offered the program code behind Else command is executed.

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.