STRINGS is the specific term given to the normal Text in the programming languages.
Strings are very important component in any program as this is the only part of the language through which the program communicate with the user.
We ask the user for the input through a STRING.
We process the user input.We return the output to the user through a STRING.
So we can understand the importance of Strings in VBA.
Many times we need to handle strings very carefully for which we need to know several types of manipulations so that we can make our application can communicate effectively.
” STRINGS ARE THE ONLY WAY THROUGH WHICH OUR APPLICATIONS COMMUNICATE WITH THE USER”
In this article, we will learn how to concatenate or join different text strings in Excel.
WHAT IS A STRING IN VBA
Simple text is also called as a String. String is a collection of characters. As we know programming languages considers the characters as the basic unit. So when characters combine , STRINGS are formed. e.g. “WELCOME TO GYANKOSH.NET” is a String.
CONCATENATE THE TEXT GIVEN IN THE CELLS D3 , D4 AND D5
CONCATENATE THE TEXT GIVEN IN THE CELLS D3,D4 AND D5 USING VBA
PLANNING THE SOLUTION
We’ll get the data from the cells and concatenate it. Then again send it to cell D6.1.Retrieve text present in D3 D4 AND D5.2.Concatenate the data.3. Put the data back in D6.
' gyankosh.net ' join the text in three given cells and output in fourth cell Sub jointext() Dim temp1 As String Dim temp2 As String Dim temp3 As String Dim temp4 As String temp1 = ActiveSheet.Cells(3, 4).Value 'ANOTHER WAY OF REACHING A CELL temp2 = ActiveSheet.Cells(4, 4).Value temp3 = ActiveSheet.Cells(5, 4).Value Range("d6″).Value = temp1 + " " + temp2 + " " + temp3 'CONCATENATING End Sub
We declare temp1, temp2 , temp3 and temp4 as strings for holding the values temporarily.
We retrieve the value with a new method.Activesheet.cells(row, column).value
All the values are in the temp variables.
We put the value in d6 and concatenate the temp1, temp2 and temp3.
RUNNING THE CODE AND OUTPUT
This was a small article on concatenating the text using vba in Excel.