VBA basics
14. Character concatenation and continuation line

Excel macro basics and applications, introduction to Excel VBA
last updated:08-15-2019

14. Character concatenation and continuation line

Some of this topic was processed by machine translation. Original


A character in one cell and a character in a cell are joined together and displayed in another cell.
This is a common case and is often done.


"Abc" in cell A1
"123" in cell B1
At this time,
Macro VBA when "abc123" is inserted in cell C1.

Character combination &(ampersand)



Sub practice1()
  Cells(1, 3).Value = Cells(1, 1).Value & Cells(1, 2).Value
End Sub

[.Value] is optional.
Connect with & (ampersand).
This is the same as the worksheet function.
In cell C1, = A1 & B1

You can also connect with + (plus).
Cells (1, 3) .Value = Cells (1, 1) .Value + Cells (1, 2) .Value
It can be written like this, but if the cell value is a number, it will be added.

Use an & (ampersand) to combine characters.
You can also combine character constants.

Sub practice2()
  Cells(1, 3).Value = Cells(1, 1).Value & "xyz"
End Sub


In the above, "xyz" is combined after the character of cell A1 and put in cell C3.
In the previous example, enter C3 cell as "abcxyz".

Continuation line _(underbar)

You can combine any number with &.



Sub practice3()
  Cells(1, 6).Value = Cells(1, 1).Value & Cells(1, 2).Value & Cells(1, 3).Value & Cells(1, 4).Value & Cells(1, 5).Value
End Sub


In the above, A1 cell to E1 cell are combined and put into F1 cell.
However, this is a little difficult to see.
The VBE screen will protrude to the right.
Therefore, it is possible to insert line breaks appropriately for easy viewing.

Sub practice3()
  Cells(1, 6).Value = Cells(1, 1).Value & _
            Cells(1, 2).Value & _
            Cells(1, 3).Value & _
            Cells(1, 4).Value & _
            Cells(1, 5).Value
End Sub


If you write _ (under bar) after a space (half-width space), you can continue to the next line.

The writing is exactly the same,
Consider the VBE screen width, and make a line break at an easy-to-read position.



Articles with the same theme "VBA basics"

11. How to use Range and Cells
12. Variables and data types (Dim)
13. Constants and type declaration characters (Const)
14. Character concatenation and continuation line
15. Four arithmetic operations and annotations (comments)
16. Iterative processing (For Next)
17. Iterative processing (Do Loop)
18. Get last row (End, Rows.Count)
19. General practice question 1
20. Conditional branch (If)
21. Conditional branch (ElseIf)



  • >
  • >
  • 14. Character concatenation and continuation line

  • If you find this site useful, please share and bookmark.


    I'm going to pay close attention to the description,
    If you have any mistakes or suggestions,「Contact Us」I hope you will let me know.
    Use the posted VBA code at your own risk.
    We are not liable for any damages such as data corruption.




    If you find this site useful, please share and bookmark.
    To the bottom of the text