I am converting an integer to string using the str() function
However, I noticed that the str() function would return an extra character to the string.
For example, MsgBox(Len(str(1)))
would return 2.
What is the extra character being appended?
To concatenate two strings using a VBA code, you need to use the ampersand. You can use an ampersand in between two strings to combine them and then assign that new value to a cell, variable, or message box. In the same way, you can concatenate more than two values as well.
The Microsoft Excel STR function returns a string representation of a number. The STR function is a built-in function in Excel that is categorized as a String/Text Function. It can be used as a VBA function (VBA) in Excel.
InStr function finds the position of a specified substring within the string and returns the first position of its occurrence. For example, if you want to find the position of 'x' in 'Excel', using the Excel VBA InStr function would return 2.
From Excel 2010 help:
"When numbers are converted to strings, a leading space is always reserved for the sign of number. If number is positive, the returned string contains a leading space and the plus sign is implied."
And sure enough this statement returns True in the debug window:
? left(str(1),1) = " "
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With