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.
- Number: The number of times to repeat the character.
- Character: A character code or a string that you want to be repeated.
To practically understand how to use the 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 cell B1.
- 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.
FORMAT | INSTR | INSTRREV | LCASE | LEFT | LEN | LTRIM | MID | REPLACE | RIGHT | RTRIM | SPACE | STRCOMP | STRCONV | STRREVERSE | TRIM | UCASE