In Excel’s Visual Basic for Applications(VBA), strings are pivotal in handling and manipulating text-based data. Strings serve as a fundamental data type used to store a sequence of characters, enabling the representation of textual information, numbers, symbols, and more. Understanding how VBA handles strings is essential for crafting powerful macros and automating tasks within Excel.
Here, we’ll learn about what is a VBA String Function and what are the different types of VBA String Functions.

VBA Strings in Excel – How to Use it?
What is a VBA String?
The string is a data type that holds a sequence of characters like the alphabet, special characters, and numbers or all of these. In VBA we can manipulate strings in such a way that we can do concatenation, reverse a string, and add or remove any string within a string. Strings are enclosed in double quotes, like “Hello, World!”.
How to Declare a String
Strings are a combination of characters. Strings can be declared in the same way as integers or characters are declared in VBA.
For example, Dim str As String, here str is a variable with the string data type.Â

Declaration of String
Assigning String value
String value should be surrounded with double quotes whenever it will be assigned to a string variable then only it is considered as string value.
For example, str = “I am Ayush“, here “I am Ayush“, is assigned in the double quotes.Â

Assigning String Value
What is Concatenation
Concatenation means the joining of two strings, into one string, using the “&” operator. The & operator is responsible for joining the strings.
For example, str = “Ayu“, str1 = “sh“, can be concatenated/joined into one string, str2 by str & str1. The final output of str2 is “Ayush“.Â

Concatenation
String Manipulation
String manipulation is a concept that provides us with different in-built functions which help to manipulate the string. There are fifteen-plus functions in string manipulation, but here we will discuss some of the most commonly used string manipulation functions.
For example, like LCase, UCase, Replace, and StrReverse.Â
1. LCase() Function
The LCase() function, returns the string after converting it into lowercase. The function takes one mandatory argument i.e. input_string.Â
Syntax of the function: LCase(input_string)
For example, “AYUSH” string has to be converted, into a lowercase string. Use LCase(“AYUSH”), and update the returned value of the function, with the original string i.e. str. The final output will be “ayush”.Â

LCase()
2. UCase() Function
The UCase() function, returns the string after converting it into uppercase. The function takes one mandatory argument i.e. input_string.
Syntax of the function: UCase(input_string)
For example, “ayush” string has to be converted, into an uppercase string. Use UCase(“ayush”), and update the returned value of the function, with the original string i.e. str. The final output will be “ayush”.Â

UCase()
3. Replace() Function
The Replace() function, replaces a part of the string with another string. The function takes three mandatory arguments i.e. input_string, string2, string3.
Syntax of the function: Replace(input_string, string2, string3)
- input_string: It is the first argument of the replace() function. It takes the required string on which you want to apply the replacement.Â
- string2: It is the second argument of the replace() function. It is the string, which will be replaced in input_string. This string should be a sub-string of input_string.Â
- string3: It is the third argument of the replace() function. It is the new string, which will be replacing the string2.Â
For example, consider a string “Codimh”, the “mh” substring can be replaced with “ng”, in the given input string. Use, Replace(“Codimh”, “mh”, “ng”), function, to replace old string with the new string. The final output of str is Coding. Â

Replace()
4. StrReverse() Function
The StrReverse() function, returns the reverse of a string. The function takes one mandatory argument i.e. input_string.
Syntax of the function: StrReverse(input_string)
For example, consider a string “Coding”, the given string can be reversed using StrReverse(“Coding”). The returned value of the given function is updated to the string str. The final output of the str is “gnidoC”.Â

StrReverse()
Substring Functions
String Functions are the text functions which are predefined to make developer job easy. There are different types of substring functions, these functions return a substring in a string. Some of them are discussed below:
1. Left() Function
The Left() function, returns the substring from the left side of the string. The function takes two mandatory arguments i.e. input_string and number.Â
Syntax of the function: Left(input_string, number)
- input_string: It is the first argument of the Left() function. It is the input string, for which the left substring has to be returned.Â
- number: It is the second argument of the Left() function. It tells the number of characters to be returned from the left start of the string.Â
For example, consider a string “Coding”, a left substring of length two can be returned using Left(“Coding”, 2). The final output of the str is “Co”.

Left()
2. Right() Function
The Right() function, returns the substring from the right side of the string. The function takes two mandatory arguments i.e. input_string and number.
Syntax of the function: Right(input_string, number)
- input_string: It is the first argument of the Right() function. It is the input string, for which the right substring has to be returned.Â
- number: It is the second argument of the Right() function. It tells the number of characters to be returned from the right start of the string.Â
For example, consider a string “Coding”, a right substring of length two can be returned using Right(“Coding”, 2). The final output of the str is “ng”.

Right()
3. Mid() Function
The Mid() function, returns a substring of any size a user wants. The function takes three mandatory arguments i.e. input_string, number1, and number2.
Syntax of the function: Mid(input_string, number1, number2)
- input_string: It is the first argument of the Mid() function. It is the input string, for which the substring has to be returned.Â
- number1: It is the second argument of the Mid() function. It tells the starting index of the substring.Â
- number2: It is the third argument of the Mid() function. It tells the number of characters of the substring.Â
For example, consider a string “Coding”, and we need to return a substring “odi”. This can be achieved using the Mid(“Coding”, 2, 3) function.Â
Note: 1-based indexing of string has been considered in the Mid() function.Â

Mid()
Length and Position
1. Len()Â Function
The Len() function, returns the length of the string. The function takes one mandatory argument i.e. input_string.Â
Syntax of the function: Len(input_string)
input_string: It is the first argument of the Len() function. It is the input string, for which the length has to be returned.
For example, consider a string “Coding”, the length of the string can be achieved by using Len(“Coding”). The final output of the program is 6.Â

Len()
2. InStr() Function
The InStr() function, returns the first position of a substring in the string. The function takes three mandatory arguments i.e. number1, input_string, and string.Â
Syntax of the function: InStr(number1, input_string, string)
- number1: It is the first argument of the InStr() function. This number tells the position of the start of the search in the input_string.Â
- input_string: It is the second argument of the InStr() function. It is the input string, in which the search has to be made.Â
- string: It is the third argument of the InStr() function. It is the string that has to be searched in the input_string.Â
For example, consider a string “Coding”, the start of the search is from index 1 i.e. character ‘C’, and the substring to be searched is “o”. This could be achieved using InStr(1, “Coding”, “o”). The final output of the program is 2.Â

InStr()
Conclusion
in Summary, VBA strings in Excel covering about strings declaration to string manipulation and how to use functions in VBA. Other than above discussed there are other functions also. VBA strings in excel are useful in efficient data handling, manipulation and also inhances spreadsheet functionality. These help in performing various jobs easily without doing everything manually especially if the sheet contains large amount of data. These also helps in error handling by reducing the chances of errors to occur.
Similar Reads
VBA Find Function in Excel
In an Excel sheet subset of cells represents the VBA Range which can be single cells or multiple cells. The find function will help to modify our search within its Range object. A specific value in the given range of cells is to search with the help of the Find function. Excel VBA provides different
5 min read
Excel VBA | sum() functions
Visual Basic for Applications (VBA) is the programming language of Excel and other offices. It is an event-driven programming language from Microsoft. With Excel VBA one can automate many tasks in excel and all other office software. It helps in generating reports, preparing various charts, graphs a
2 min read
Trapping Dynamic Ranges in Excel VBA
Dynamic Ranges give the flexibility to work with more range of cells as compared to a specific range of cells which usually limits us to work with a particular range of cells. As the size of the data may change in an excel sheet so it is also necessary to change the range in the code dynamically for
3 min read
Programming Charts in Excel VBA
VBA stands for Visual Basic for Applications and it is developed by Microsoft. MS Excel and many other Microsoft applications like word, access, etc have this language integrated into them using which one can do various things. VBA can be used in MS Excel through the code editor in its developer tab
4 min read
Excel VBA | count() functions
Visual Basic for Applications (VBA) is the programming language of Excel and other offices. It is an event-driven programming language from Microsoft. With Excel VBA one can automate many tasks in excel and all other office software. It helps in generating reports, preparing various charts, graphs a
2 min read
Introduction to MS Excel
Since the release of the first version of Excel in 1985, this spreadsheet program has received various updates, and nowadays it is one of the most used spreadsheet programs. But the question is, what is actual Microsoft Excel? What are the use cases of this spreadsheet program? This introduction gui
9 min read
VBA Arrays in Excel
Arrays are used to store data of similar data types. Suppose there are 300 students rather than declaring 300 variables for students, we can declare one array where we can store 300 elements. In this article, we will learn about excel VBA arrays. Declaration of Array Declaring an array is similar to
5 min read
Worksheets in Excel
If you're new to MS Excel, you've likely heard the term "worksheet." But have you ever wondered what an Excel worksheet actually is? So, in a spreadsheet program, a worksheet is a collection of cells (it is a basic data unit in the worksheet) where you can store and manipulate data. By default, ever
5 min read
What is Excel?
Ever wondered, "What is Excel?" If youâve searched for it, you are likely to have. Excel is Microsoftâs powerful spreadsheet program and a component of MS Office for business. It is a go-to tool for organizing data, calculating numbers, and presenting information clearly. The popularity behind this
9 min read
Multidimensional Arrays in Excel VBA
Multidimensional Arrays are used to store data of similar data types of more than one dimension. A multidimensional array has a dimension up to 60 but usually, we don't use arrays of dimensions more than 3 or 4. Here, we will see how to declare a multidimensional array in many ways and also how to c
2 min read