Convert integer to String

rkcim

Board Regular
Joined
Nov 19, 2003
Messages
87
I have an integer and I converted it to a string

Here is a basic example of my problem:
Dim i As Integer
i = 5
MyString = str(i)

Now MyString = " 5"
It has a space in front of the 5. How do get rid of it? Is there a better function than str?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Ok this one should be easy rkcim:

Dim i As Integer
i = 5
MyString = LTrim(str(i))

Now MyString = "5"
 
Upvote 0
Hi,

You might like to read about the various Type Conversion Functions (see the VBA Help files).

For example:
Code:
Sub test()
    Dim i As Integer, MyString As String
    
    i = 5
    MyString = CStr(i)
    MsgBox ":" & MyString
    
End Sub
HTH
 
Upvote 0
The easiest way I've found so far: use "CONCATENATE" Excel function, i.e.,

=CONCATENATE( B1, "" )

where B1 is a number.
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,500
Members
449,090
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top