Excel VBA Concatenation Operators
Last Updated :
19 Jul, 2021
VBA in Excel stands for Visual Basic for Applications which is Microsoft's programming language. To optimize the performance and reduce the time in Excel we need Macros and VBA is the tool used in the backend. Concatenation means to join two or more data into a single data. There are various ways we can perform concatenation in Excel using built-in functions, operators, etc.
Some helpful links to get more insights about concatenate and using VBA in Excel :
- Record Macros in Excel
- CONCATENATE in Excel
- How to Create a Macro in Excel?
In this article, we are going to see about concatenate operators and how to use VBA to concatenate strings as well as numbers.
Implementation :
In the Microsoft Excel tabs, select the Developer Tab. Initially, the Developer Tab may not be available.
The Developer Tab can be enabled easily by a two-step process :
- Right-click on any of the existing tabs at the top of the Excel window.
- Now select Customize the Ribbon from the pop-down menu.

- In the Excel Options Box, check the box Developer to enable it and click on OK.
- Now, the Developer Tab is visible.
Now, we need to open the Visual Basic Editor. There are two ways :
- Go to Developer and directly click on the Visual Basic tab.
- Go to the Insert tab and then click on the Command button. Drag and insert the command button in any cell of the Excel sheet.
Now, double-click on this command button. This will open the Visual Basic Application Editor tab, and we can write the code. The benefit of this command button is that just by clicking on the button we can see the result of concatenation, and also we don't need to make any extra Macro in Excel to write the code.
Another way is by right-clicking on the command button and then select View Code as shown below :

CONCATENATE Operators:
To concatenate operator mostly used in Excel is "&" for numbers as well as strings. But for strings, we can also use "+" operator to concatenate two or more strings.
The syntax to concatenate using formula is :
cell_number1 & cell_number2 ; without space in between
cell_number1 & " " & cell_number2; with space in between
cell_number1 & "Any_Symbol" & cell_number2 ; with any symbol in between
cell_number(s) & "string text" ; concatenate cell values and strings
"string_text" & cell_number(s) ; concatenate cell values and strings
CONCATENATE Two Numbers:
Example 1: Take any two numbers as input and concatenate into a single number.
The code to concatenate two numbers in Excel is :
Private Sub CommandButton1_Click()
'Inserting the number num1 and num2
Dim num1 As Integer: num1 = 10
Dim num2 As Integer: num2 = 50
'Declare a variable c to concatenate num1 and num2
Dim c As Integer
'Concatenate the numbers
c = num1 & num2
MsgBox ("The result after concatenating two numbers are: " & c)
End Sub
Run the above code in VBA and the output will be shown in the message box.
Output :
The result after concatenating two numbers are: 1050
You can also click on the command button and the same message will be displayed.
Example 2: Say, now we take two numbers from the cells of the Excel Sheet and store the result back in the Excel sheet. This time we are not going to use the command button.
Step 1: Open the VB editor from the Developer Tab.
Developer -> Visual Basic -> Tools -> Macros
Step 2: The editor is now ready where we can write the code and syntax for concatenation.
Now write the following code and run it.
Sub Concatenate_Numbers()
'Taking two variables to fetch the two numbers and to store
Dim num1 As Integer
Dim num2 As Integer
'Fetching the numbers from Excel cells num1 from A2 and num2 from B2
num1 = Range("A2").Value
num2 = Range("B2").Value
'Find the concatenate and store in cell number C2
Range("C2").Value = num1 & num2
End Sub
CONCATENATEDConcatenate Two Or more strings:
We can use either "+" operator or "&" operator.
Example 1: Let's concatenate the strings "Geeks", "for", "Geeks".
Repeat Step 1 as discussed in the previous section to create a new VBA module of name "Concatenate_Strings"
Now write either of the following codes and run it to concatenate two or more strings.
Sub Concatenate_Strings()
'Taking three variables to fetch three strings and to store
Dim str1 As String
Dim str2 As String
Dim str3 As String
'Fetching the strings from Excel cells
str1 = Range("A2").Value
str2 = Range("B2").Value
str3 = Range("C2").Value
'Find the concatenate and store in cell number D2
Range("D2").Value = str1 + str2 + str3
End Sub
Sub Concatenate_Strings()
'Taking three variables to fetch three strings and to store
Dim str1 As String
Dim str2 As String
Dim str3 As String
'Fetching the strings from Excel cells
str1 = Range("A2").Value
str2 = Range("B2").Value
str3 = Range("C2").Value
'Find the concatenate and store in cell number D2
Range("D2").Value = str1 & str2 & str3
End Sub
CONCATENATED
Example 2: Let's concatenate three strings and add in different lines and display them in a message box this time.
Create a new module and write the code. The keyword used for adding the string in the next line is vbNewLine.
The code is :
Sub Concatenate_DifferentLines()
'Taking three variables to store
Dim str1 As String
Dim str2 As String
Dim str3 As String
'Initialize the strings
str1 = "The best platform to learn any programming is"
str2 = "none other than GeeksforGeeks"
str3 = "Join today for best contents"
'Display the concatenated result in a message box
MsgBox (str1 & vbNewLine & str2 & vbNewLine & str3)
End Sub
Example 3: Let's concatenate two strings with space in between by taking an example of the full name of a person which contains First Name and Last Name.
Create a new module Concatenate_Strings_Space and write the following code :
Sub Concatenate_Strings_Space()
'Taking two variables to fetch two strings and to store
Dim fname As String
Dim lname As String
'Fetching the strings from Excel cells
fname = Range("A2").Value
lname = Range("B2").Value
'Find the concatenate and store in cell number C2
Range("C2").Value = fname & " " & lname
End Sub
Similar Reads
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Steady State Response In this article, we are going to discuss the steady-state response. We will see what is steady state response in Time domain analysis. We will then discuss some of the standard test signals used in finding the response of a response. We also discuss the first-order response for different signals. We
9 min read
Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca
7 min read
3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power
13 min read
What is Vacuum Circuit Breaker? A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac
13 min read
AVL Tree Data Structure An AVL tree defined as a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees for any node cannot be more than one. Example of an AVL Tree:The balance factors for different nodes are : 12 :1, 8:1, 18:1, 5:1, 11:0, 17:0 and 4:0. Since all differences
4 min read
CTE in SQL In SQL, a Common Table Expression (CTE) is an essential tool for simplifying complex queries and making them more readable. By defining temporary result sets that can be referenced multiple times, a CTE in SQL allows developers to break down complicated logic into manageable parts. CTEs help with hi
6 min read