VBA String Operator

String operators are used to manipulate string data. A string can include alphabets, numbers, and special characters in a sequence. A string’s special advantage is that it can contain all kinds of characters in a single string.

For example, you can concatenate the value of  “Hello” and “World” in a single string.

Examples of Strings in Excel

Alphabets

Str1 = “AnyText”

Numbers

Str2 = “17”

Special Characters

Str3 = “!@#$”

String Operator in VBA

Concatenate (&): Two Strings or Values are Combined Together Using a Concatenate Operator. This is one of

str1 = “Hello”

str2 = “World”

For Example, strValue = str1 & ” ” & str2

Output: Hello World

Example

Step 1: Add a Button to the Excel Sheet as we Have shown in the Previous Article.

1.  Change the Name Property Such as Btnconcatenate.

button

Step 2: on the Button and Select the View Code Option. You will get the code Window as Shown in the Below Screenshot.

command

Step 3: Write the Following Code in Between Private Sub cmdButtonConcatenate_Click and End Sub as follows.

MsgBox “Hello” & “World”, vbOKOnly, “Concatenate Operator”

script

Step 4: Click on the Save Button and Close the Code Editor Window.

Step 5: Turn off the Design Mode Button.

ribbon

Step 6: The Indicator will Change into a white Background From the Greenish-Colored Background as Shown in the Screenshot.

ribbon2

Step 7: Click on the cmdButtonConcatenate button.

Step 8: Execute the Above Code and get the Type of Output Shown in the Below Screenshot.

MsgBox_HelloWorld


Notice: Trying to access array offset on value of type int in /home2/bestrev2/public_html/xlautomation/wp-includes/class-wp-list-util.php on line 170

Notice: Trying to access array offset on value of type int in /home2/bestrev2/public_html/xlautomation/wp-includes/class-wp-list-util.php on line 170

Notice: Trying to access array offset on value of type int in /home2/bestrev2/public_html/xlautomation/wp-includes/class-wp-list-util.php on line 170

Leave a Comment

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