Excel VBA: If Cell Contains Value Then

In this article, we will look at how to automate the launching of a particular action when a cell on the worksheet contains a particular value. There’re three ways that we can do this with; InStr, Like, and Find. Example 1: INSTR Instr is a

All About Autofilter in VBA

We all are very well aware of the efficiency of MS Excel. However, to further enhance its efficiency, VBA macros come in handy. Without using macros, you can easily filter out information in a dataset, based on criteria, using the ‘Filter’ feature within the ‘Data’

Call Sub vs. Functions in VBA

Introduction In the MS Excel’s Visual Basic Editor, Sub is a statement, like a function fun(), that performs a specific task. A sub is a piece of code that performs a specific task and does not return a result. The purpose of a subroutine is to

Can You Handle It? — VBA InputBox Cancel

Out of all the challenges you might face in MS Excel VBA, there is one that may very well be the universal “Achilles Heel.”  The user…  To illustrate this, consider the following scenario:  You just spent several days building and successfully testing a great MS

How to Fix Compile Error: Expected: End of Statement

Introduction Every programming language has its own grammar and vocabulary — technically known as syntax. Having a mastery of any language implies that you have a sound knowledge of its syntax. As a beginner in VBA, you might be confronted with frustrating errors like the

How to Freeze Panes Using Excel and VBA

Introduction Freezing panes is a very handy feature that is indispensable in any Excel workbook that has more than few columns or few rows.  In this article, we will take a look at exactly how to utilize the Freeze Pane feature in both Excel and

How to Clear the Immediate Window

Introduction In a previous article titled “VBA print to console,” you saw the use of the immediate window in VBA. You learned from that article that the VBA immediate window is a kind of playground where the VBA programmer can test code to see whether

VBA If Statements with Multiple Conditions

Introduction One of the most common things to do in coding is to build logic that checks for the occurrence of multiple conditions. As a coder, whether novice or experienced, hopefully you agree that this is one of the most common coding tasks. In VBA,

Cross Products with Excel and VBA

Microsoft Excel does not have the built-in worksheet functions to calculate the cross product of two vectors. Therefore, some techniques are required to do the calculation — either by setting up your own formula in a worksheet or by creating a custom VBA function. The