All posts by Mahmoud Mostafa

No Thumbnail

If/Else Then Do Nothing in Excel VBA

When we don’t want to do anything in an If-then-else statement, believe it or not, we can simply not place any code! This is the most straightforward way to ‘do nothing’ in VBA. VBA does not have a specific statement that can be used for

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

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

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,

How to Use NumberFormat in VBA

Description FormatNumber is a property of the Range object of Excel. The Range object can be considered as a cell or a group of cells — be that a single cell, a column in an Excel table, or the UsedRange of an Excel sheet. The

How to Use IF OR Statements in VBA

In VBA, IF OR is the combined utilization of the IF statement and the OR keyword. Particularly, the OR keyword is used to construct the logic of the condition statement. The syntax for the combined IF OR statement is as follows: IF [condition statement 1]

The Complete Guide to Regex in VBA

Regular Expressions (Regex) are a pattern that is used to find matches within strings. This is very useful when you want to validate, replace, or extract data from strings. In Excel, regular expressions can be used when working with VBA. Matching Characters The Pattern is

The TextFrame Object in VBA with Examples

A TextFrame object is used to manipulate various elements of the text frame –basically a box of text — related to shape objects. When we have a shape object (ex. rectangle, circle, etc.), we can control the text associated with the shape through the TextFrame

How to use the RND Function in VBA

Introduction The RND function is used to generate a random number between 0 and 1. Generating a random number has applications in domains such as gambling, statistical sampling, computer simulation, or to — generally speaking — create unpredictable results for any other purpose. Of course,