How to use VbCrLf in Excel VBA

In this tutorial we’ll learn how to use VbCrLf in our VBA code. Let’s take a look at the dataset show above.

We have first name and last names in two columns and we are going to join these names in the third column but with a Line Break in between them using VbCrLf. Let’s see how to do it by following the simple steps mentioned below; 

Microsoft Office provides support for programmers through its own programming language Visual Basic for Applications also known as VBA. We can use this programming language for automating our tasks in Microsoft Office Applications, i.e., Excel, Word, PowerPoint, Access etc. VbCrLf is a very useful character constant in VBA which means “Visual Basic Carriage Return Line Feed”.

Step 1 – Open the VBA Editor by pressing ALT+F11 or through Developer Tab

– In Excel’s main menu, click on the Developer tab and then click on Visual Basic.

Step 2 – Insert the Module and write the code

– The previous step will open the VBA editor. In this editor’s main menu tabs, click on Insert and then choose Module. This will insert a module named Module1 by default and open a white blank space to write the code into it.

– This will insert a blank module in the editor where we will insert the code to join the first and last names with Line Break in between using VbCrLf. The code snippet is available at the end of this tutorial.

Step 3 – Run the code and observe the output

– Now let’s run the code by pressing the shortcut key F5 inside the VBA Editor. This will run the code and we’ll get the desired output in the Excel File.

– We wanted to join the first and last names with a line break in between them using the VbCrLf constant. We can see that the code has produced the desired output by going through the first and last names though a For loop and joining the names in column C by inserting a VbCrLf (Line Break or Line Feed) between the names.

The Code Snippet

Here is the code that is used in this tutorial;

Leave a Comment