HomeVBA Functions LIST (Category Wise)How to use the VBA STRING Function (Syntax + Example)

What is VBA STRING Function

The VBA STRING function is listed under the text category of VBA functions. When you use it in a VBA code, it repeats a character number of times and returns that string in the result, and if you prefer to supply more than one character it only repeats the first character out of them.

how to use it

To use VBA's STRING function you need to understand its syntax and arguments:


String(Number, Character)


  • Number: The number of times to repeat the character.
  • Character: A character code or a string that you want to be repeated.

Example to use STRING Function in VBA

To practically understand how to use VBA STRING function, you need to go through the below example where we have written a vba code by using it:

Sub example_STRING()
Range("A1").Value = String(5, "Y")  
End Sub

In the above code, we have used STRING to create a string using the character “Y” and specify to repeat it 5 times and it has returned the result in the cell B1.


Below are some important points which you need to take care while using STRING function in VBA.

  • If the “number” supplied is a negative number then VBA will return a run-time 5 error.
  • If the “character” is Null, it will return Null.

Related Functions

About the Author

puneet one point one

Puneet is using Excel since his college days. He helped thousands of people to understand the power of the spreadsheets and learn Microsoft Excel. You can find him online, tweeting about Excel, on a running track, or sometimes hiking up a mountain.