Return to VBA Code Examples

VBA Join Function

Written by

Editorial Team

Reviewed by

Steve Rynearson

Last updated on July 19, 2021

Join Description

Joins a number of substrings into a single string.

Simple Join Examples

Sub Join_Example()
    Dim strFullName As String
    Dim arrName(0 To 2) As String
    arrName(0) = "Michael"
    arrName(1) = "Pauling"
    strFullName = Join(arrName)
    MsgBox strFullName
End Sub

This will display as following.

Join Syntax

In the VBA Editor, you can type¬† “Join(” to see the syntax for the Join Function:

The Join function contains 2 arguments:

SourceArray: 1d array containing substrings to be joined.

Delimiter: [Optional] Delimiter. If omitted, the space character (” “) is used.

Examples of Excel VBA Join Function

Sub JoinArray_Example1()
    Dim strFullPath As String
    Dim arrPath(0 To 2) As String
    arrPath(0) = "C:"
    arrPath(1) = "Users"
    arrPath(2) = "Public"
    strFullPath = Join(arrPath, "\")
End Sub

Result: C:\Users\Public

Sub JoinArray_Example2()
    MsgBox Join(Array("A", "B", "C"), ", ")
End Sub

Result: “A, B, C”

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as

Learn More!

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)

Free Download

Return to VBA Code Examples