Tag: VBA

VBA – How to avoid naming variables with non-latin alphabet characters (special letters)

Writing code in the local language is actually taught by about 100% of the German VBA books, which I have read. Which is “kind of ok”, if the VBA code only works on German computers. However, if this is not

Tagged with: , ,

VBA – Color Only Half of the Border of an Excel Cell

Coloring the border of an Excel cell is a trivial task. The LineColor feature in Excel is easy to use out of the box: However, whenever half of the cell needs to be colored, the trick is a bit more tough

Tagged with: , , , , ,

VBA – Longest Palindromic Subsequence Algorithm with Excel – GIF

After writing about the longest palindromic substring, now it is time to see the longest palindromic subsequence. What is the difference? Pretty much, if we take the word abracadabra: the longest substring is ada in abracadabra the longest subsequence is

Tagged with: , , , , ,

VBA – Longest Palindromic Substring Algorithm with Excel – GIF

The longest palindromic substring algorithm exists since 1975. It is different (and easier) than the longest palindromic subsequence. The idea of the substring is to return “anana”, if “bananazorro” is given. This is achieved with a 2 dimensional boolean array matrix and

Tagged with: , , , , , ,

VBA – Insert an image/picture in Excel and position it correctly

Inserting an image to Excel with VBA is actually one line: ThisWorkbook.Worksheets(1).Pictures.Insert ("C:\Users\myPic.png") The interesting part happens, when it should be correctly positioned. In order to position it the way we want, we need to give 3 parameters – the image

Tagged with: , , , , ,

VBA – Put a Collection inside a Scripting Dicitonary OR Make an Updateable ComboBox

The idea of the article is to make an updateable combobox, which takes all the keys of column A and writes them to the ComboBox. Then, upon selection of the corresponding values in the combobox, it provides the corresponding values

Tagged with: , , , , ,

VBA – ListBox in Excel – Adding, Editing and Removing Data

The idea of the article is to show how to add, edit and remove specific entries of the ListBox in Excel through VBA: ListBox is a control, which is available through Developer>Insert>ActiveX>ListBox in Excel: Once you add it, it has

Tagged with: , , , , , , , ,

VBA – Reverse words in a sentence

Reversing words in a sentence with VBA in Excel is quite easy, using the built-in StrReverse function. StrReverse takes a string and reverses it. Thus, “VitoshAcademy.com” becomes “moc.ymedacAhsotiV”: The idea of reversing the order of the words in a sentence

Tagged with: , , , ,

VBA – Benford Analysis (First-Digit Law)

Long time ago, an astronomer called Benford was taking a look at logarithm books, noticing that the earlier pages (starting with 1) are pretty much more worn out than the later ones. He thought about the result, and managed to

Tagged with: , ,

VBA – Dictionary

VBA has a dictionary structure. Dictionary is an object, and it can be referenced either with early binding or with a late binding, referring to Microsoft Scripting Runtime: What is a dictionary? This is the Microsoft definition of the VBA

Tagged with: , , , , ,

Top VBA-Excel errors

Some months ago #VBA was finally considered the most dreaded language in the 2019 StackOverflow survey: One of the reasons for this, is probably that #VBA is quite too easy to enter, thus plenty of non-IT professionals feel fascinated about

Tagged with: , , , ,

VBA – Abstract classes. Classes, that cannot be instantiated.

There are parts of #VBA, that can scare any VBA developer, who has not bumped into other languages. Although, the “abstract class” term is quite popular in C# and other languages, and is quite easy to be created, in VBA,

Tagged with: , , , , ,

C# – Find the Biggest Square in a Matrix – What can Excel and VBA add to it?

Finding the biggest square of specific units in a given matrix of these units is a standard dynamic programming problem. The examples in Google for it are above 18 million, thus I would simply show how it is done with

Tagged with: , ,

VBA – How to copy a new object in VBA, without copying its reference

Copying an object in VBA to a new object is somehow tough. If you use  Set foo = bar then, both foo and bar would be pointing to the same address in the heap. And if you change the properties of one, you would automatically

Tagged with: , ,

VBA – Environmental Variables

The environmental variables are a dynamic-named values that can affect the way running processes will behave on a computer. With other words, if you want to see them in your PC, simply open the command prompt and write the nice word

Tagged with: ,

VBA – Data scraping from Internet with Excel – Part 2

Some time ago I wrote an article for Data scraping from Internet with Excel , which was scraping book information from amazon.com, based on a given word. Thus, for a keyword as “VBA”, this is the data, printed in the immediate

Tagged with: , , ,

VBA – Animation with Excel

Animation consists of some pictures. In general, there are about 24 pictures per second, in order to do the “magic”. This could be easily automated with Excel, using  Application.Wait (Now + #12:00:01 AM#), if we agree to make it a bit old-fashioned, with 1 picture

Tagged with: , ,

VBA – Extracting text from string between two identical characters using VBA

Automation of Excel is actually pretty interesting task. VBA is indeed the best built-in tool for this and although there is a lot of “hate” towards it it really deserves to be taken into account seriously, at least for small daily

Tagged with: , , ,

VBA – RegEx Used to Take the Valuable Data Out

Writing for RegEx in VBA is sometimes a good idea and sometimes a bad idea. Anyway, if you need to write one, you better be careful. These are the RegEx articles in VBA in VitoshAcademy so far: https://www.vitoshacademy.com/vba-regex-in-excel-part-2/ https://www.vitoshacademy.com/vba-regex-in-excel/ So,

Tagged with: , ,

VBA – AutoMacro AddIn – VBA Software Review

VBA is extremely underestimated programming language. I have always been thinking that there are almost no real #VBA developers, because the “real” developers do not want to do some meaningless “macro” stuff and the people who work with #VBA are

Tagged with: , , ,

VBA – How to check messages for specific words before sending them with Outlook

Gmail has the option to revert a message for about 10 seconds after you have sent it: Well, Outlook with VBA can do similar things, if you are willing to program it a bit with VBA. Let’s say that you

Tagged with: , , ,

Add comments in Excel with VBA

Adding comments with VBA is somehow quite a trivial task, if you already have the text of the comment and you are allowed to delete the comment if it is present. In general, the only difficult part is the check,

Tagged with: , , ,

VBA – Data scraping from Internet with Excel

Sometimes, you may need to scrape some structured data from the internet with Excel. Honestly, Excel. Honestly, Excel should be your last weapon of choice there, as far as it is really not a web-scraping software. Still, it is quite

Tagged with: ,

VBA – Read different levels of XML

After the article here for VBA – Select a Single Node XML now I am writing an update from it, which shows how to loop through all the nodes that we are interested in and get data from them. The XML is

Tagged with: , , ,

VBA – Fill Numbers in a Given Range

So, the idea is the following –  imagine that you have an NxN range, which should be filled out with consecutive numbers. Thus, if the range is 6×6, you start filling the numbers normally and once you reach the 6.

Tagged with: , , ,

Format and Color Text in Excel Cell with VBA

Formatting a substring of a string in an Excel Cell is actually quite a challenging task. There are two ways to do it – select part of the substring that you wish to format and change its color. Then make

Tagged with: , ,

How to Change Tab Color in Excel with VBA

Changing tab color of Excel is somehow useful. With VBA, it is easily programmed, as far as one can use the macro recorder to see the correct way to do it. However, if you need to change the color of

Tagged with: , ,

VBA – Using Parameters in a VBA SQL Query To a Database

In this article I will simply use the code from my first guest author Mathieu, to build up some small working solution, that uses parameters: So, the two classes, provided by Mathieu are here as well  GitHub, named AdoValueConventer.cls and SqlCommand.cls.

Tagged with: , , ,

VBA – Select Multiple Cells in a Excel Range

Selecting multiple cells in Excel through VBA may be quite a difficult task. Although, using Select is not always a good practice, sometimes it should be done. To generate some numeric values, let’s run the following:

After this, we have

Tagged with: , ,

VBA – Simulation of Rolling Dices

Excel and VBA are a powerful tool for simulation. The idea is to simulate dice throwing and to keep the best N throws as our score. Other model variables are Times I roll, which stands for how many times do

Tagged with: , , , ,
Top