VBA Concatenate Strings

VBA Concatenate Strings in Excel

VBA Concatenate Strings in Excel. We can Append multiple strings into single string by using ‘&’ and ‘+’ operators. All string values are enclosed with double quotation(“”) marks. We have to add space before and after & and + operators. We can append special symbols also.

Syntax to append Strings in Excel VBA

Here is the syntax to concatenate multiple strings using & and + operators in Excel VBA.

Using & Operator

String1 & String2 & ... & StringN

Using + Operator

String1 + String2+...+ StringN

Macro to append Strings using ‘&’ operator in Excel VBA

Let us see the example macro to Concatenate or append Strings using ‘&’ in Excel VBA.

'VBA Append Strings using '&' operator in Excel
Sub VBA_Append_Strings()
    
    'Variable Declaration
    Dim String1 As String, String2 As String, String3 As String
    Dim Result As String
    
    String1 = "Thanks for"
    String2 = " visiting "
    String3 = "our blog."
    
    'Concatenate Strings
    Result = String1 & String2 & String3
    
    MsgBox "Appended Multiple Strings using & operator: " & vbCrLf & Result, vbInformation, "VBAF1"

End Sub

Here is the output screenshot for above macro procedure.

VBA Append Strings

Macro to append Strings using ‘+’ operator in Excel VBA

Let us see the example macro to Concatenate or append Strings using ‘+’ in Excel VBA.

'VBA Concatenate Strings using '+' operator in Excel
Sub VBA_Concatenate_Strings()
    
    'Variable Declaration
    Dim String1 As String, String2 As String, String3 As String
    Dim Result As String
    
    String1 = "22"
    String2 = "44"
    String3 = "66"
    
    'Concatenate Strings
    Result = String1 + ":" + String2 + ":" + String3
    
    MsgBox "Concatenated Multiple Strings using + operator: " & vbCrLf & Result, vbInformation, "VBAF1"

End Sub

Here is the output screenshot for above macro code.

Concatenate Strings

Instructions to use Macro

Here are the instructions to use above macro in Visual basic editor.

  • Open Visual Basic Editor(VBE) by clicking Alt +F11
  • Go to code window by clicking F7
  • Copy above specified macro or procedure
  • Paste above copied code in code window
  • Run macro by clicking F5 or Run command
  • You can see output on the screen
  • Find above specified output screenshot.

Other Useful VBA Text and String Functions

We have used Date and DateDiff VBA functions. Click on below specified links to learn more about VBA functions.

VBA Text and String Functions




4 thoughts on “VBA Concatenate Strings in Excel”

Leave a Comment

Your email address will not be published. Required fields are marked *