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.

Variables, data types, constants …

Variables are placeholders within computer memory that are aimed to store values ​​of different types of data, such as: numbers, text, logical values, date/time … Although this is not necessary, for better memory utilization, you need to declare them at the beginning of the program and assign them a data type. Variables that will have fixed values ​​during program execution are called constants.

Introduction to VBA

VBA (Visual Basic for Applications) is a programming language that exists “under the hood” of MS Office applications. Therefore, it is a part of Excel and allows users to create new features, introduce additional functionality and automate work with spreadsheets. This is the first of the posts in which I will try to teach you the basics of VBA programming. Important advice: before you decide to write code learn Excel and try to find out if what you want to get is already there!

Calculating the distance

How to calculate distance between the two places on the map? The simplest way is by using the formula for calculating the haversine, which for the given coordinates returns the distance of the points on the sphere. However, this is the air distance. If you are planning to take off on the road, you are surely interested in getting from point A to point B by traffic. In the following text I will show you how to use Google Maps to calculate distance.