How to Concatenate String and Integer in Excel Using VBA

Table of Contents

Table of Contents

In Excel, we often need to merge a string with an integer into a single cell for reporting or dashboard purposes. VBA provides two main operators for this: the ampersand (&) and the addition (+) operator, each with its own behavior and requirements. 

Key Takeaways

To concatenate a string and an integer, follow these steps:

➤ Open the VBA editor and insert a new module.
➤ Use either & or + operator to join a string and an integer. If using +, convert the number using the CStr function.
➤ Loop through your dataset and write the result to a target column.

In this article,  we will show how to concatenate strings and integers in VBA using both the ampersand (&) and addition operator (+).

Download Practice Workbook
1

Concatenate String and Integer using Ampersand Operator in VBA

The ampersand (&) operator in VBA is the standard method for joining strings and integers into a single output. It can automatically handle mixed data types, making it safer and more reliable than the addition (+) operator. We use this method when we merge text-like names with numeric values, such as IDs, typically for generating readable summaries in Excel.

We have a dataset of employees of a company with their names and unique Employee IDs. We will concatenate the employee’s full name with their ID  using the VBA  ampersand (&) operator

Steps:

➤ Open your Excel sheet that contains your string and integer separately. For example, we have taken a dataset that contains First Name in Column A, Last Name in Column B, Employee ID in Column C, and Info in Column D (Blank).

Concatenate String and Integer using Ampersand Operator in VBA

Press  Alt  +  F11  to open the Visual Basic for Applications (VBA) editor in Excel.

Concatenate String and Integer using Ampersand Operator in VBA

Go to the menu bar → InsertModule to create a new code module.

Concatenate String and Integer using Ampersand Operator in VBA

➤ A new code window will open where you will paste your VBA script.

Concatenate String and Integer using Ampersand Operator in VBA

Copy and paste the following code into the module:

Sub Concatenate_StringInteger()
Dim i As Integer
Dim firstName As String
Dim lastName As String
Dim empID As Integer
Dim result As String
' Loop through rows 2 to 9
For i = 2 To 9
firstName = Cells(i, 1).Value       ' Column A: First Name
lastName = Cells(i, 2).Value        ' Column B: Last Name
empID = Cells(i, 3).Value           ' Column C: Employee ID
' Concatenate using Ampersand
result = firstName & " " & lastName & " " & empID
' Output to Column D: Info
Cells(i, 4).Value = result
Next i
End Sub

Concatenate String and Integer using Ampersand Operator in VBA

➤ Back in Excel, go to the Developer tab.  If the Developer tab is not visible, click File.

Concatenate String and Integer using Ampersand Operator in VBA

Choose more → Options.

Concatenate String and Integer using Ampersand Operator in VBA

Click on the Customize Ribbon.

Concatenate String and Integer using Ampersand Operator in VBA

Check Developer, and click OK.

Now, go to the Developer tab.

 ➤ Click on Macros.

➤ Select Concatenate_StringIntegerRun

➤ Column D (Info) will now show values like: John Mathew 907, Sarah Khan 812, etc.

Note:
➥ Make sure there are no blank cells in First Name, Last Name, or Employee ID columns.
➥ You can extend the loop range if your dataset has more rows (e.g., change For i = 2 To 9 to For i = 2 To 100).
➥ This method uses Ampersand (&), which is preferred for string concatenation in VBA.


2

Concatenate String and Integer Using the Addition Operator in VBA

The addition operator (+) in VBA can be used to join strings and integers, but it requires converting the number to a string first. This method is good when we work with mixed data types like names and ID numbers, where direct concatenation may cause errors or unexpected results. Unlike the ampersand (&), which handles mixed types automatically, the + operator needs CStr to ensure compatibility.

We have a dataset of students with their names and unique enrollment IDs. We will concatenate the student’s full name (string) with their ID (integer) using VBA and the Addition (+) operator.

Steps:

➤ Open your Excel sheet that contains your string and integer separately. For example, we have taken a dataset that contains First Name in Column A, Last Name in Column B, Enrollment ID in Column C, and Info in Column D (Blank).

Concatenate String and Integer Using the Addition Operator in VBA

Press  Alt  +  F11  to open the Visual Basic for Applications (VBA) editor in Excel.

Concatenate String and Integer Using the Addition Operator in VBA

Go to the menu bar → InsertModule to create a new code module.

Concatenate String and Integer Using the Addition Operator in VBA

➤ A new code window will open where you will paste your VBA script.

Concatenate String and Integer Using the Addition Operator in VBA

Copy and paste the following code into the module:

Sub Concatenate_StringIntegerPlus()
    Dim i As Integer
    Dim firstName As String
    Dim lastName As String
    Dim empID As Integer
    Dim result As String
    ' Loop through rows 2 to 9
    For i = 2 To 9
        firstName = Cells(i, 1).Value       ' Column A: First Name
        lastName = Cells(i, 2).Value        ' Column B: Last Name
        empID = Cells(i, 3).Value           ' Column C: Enrollment ID
        ' Concatenate using Addition (+) after converting integer to string
        result = firstName + " " + lastName + " " + CStr(empID)
        ' Output to Column D: Info
        Cells(i, 4).Value = result
    Next i
End Sub
Explanation
CStr(empID) converts the integer to a string so it can be added to other strings using +.
➥ The result is stored in Column D (Info) as a single string like "Ethan Brooks 1001".

Concatenate String and Integer Using the Addition Operator in VBA

➤ Back in Excel, go to Developer.

Concatenate String and Integer Using the Addition Operator in VBA

➤ Click on Macros.

Concatenate String and Integer Using the Addition Operator in VBA

➤ Select Concatenate_StringIntegerPlus Run

Concatenate String and Integer Using the Addition Operator in VBA

Column D (Info) will now show values like: Ethan Brooks 1001, Olivia Carter 1002, etc.

Concatenate String and Integer Using the Addition Operator in VBA

Note:
➥ Using + for string concatenation is less common than &, and may cause errors if any variable is not properly converted to a string.
➥ Always use the CStr function to convert numeric values before using + for concatenation.
➥ Make sure there are no blank cells in First Name, Last Name, or Enrollment ID columns.


Frequently Asked Questions

Which operator is safer to use: & or +?

The ampersand (&) is safer because it automatically handles mixed data types.

Why use CStr with the + operator?

Because + expects both operands to be strings, CStr() ensures the integer is treated as text.

Can I concatenate multiple fields in one line?

Yes, you can combine several strings and numbers using either operator, separated by spaces or symbols.


Concluding Words

Concatenating strings and integers in VBA is a simple yet essential method for generating readable outputs. Using the ampersand operator or the addition operator with CStr allows us to merge text and numbers efficiently within Excel macros. Also, you can download the text files and datasets that we have used in this article to practice on your own.

Facebook
X
LinkedIn
WhatsApp
Picture of Shihab Shahriar

Shihab Shahriar

Md. Shihab Uddin holds a Graduation in Crop Science and Technology and is pursuing a Postgraduate degree in Soil Science from the University of Rajshahi. With 4+ years of Excel and Google Sheets experience, he specializes in formulas, data cleaning, lookups, automation, VBA, formatting, and file management. He has authored 100+ in-depth Excel articles and is skilled in Power Automate, RPA, and Python. He enjoys creating efficient workflows and solving real-world data problems.
We will be happy to hear your thoughts

      Leave a reply

      Excel Insider
      Logo