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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

rkcim

Board Regular
Joined
Nov 19, 2003
Messages
87
Ok this one should be easy rkcim:

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

Now MyString = "5"
 

Richie(UK)

MrExcel MVP
Joined
May 17, 2002
Messages
3,329
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
 

Yakov

New Member
Joined
Dec 28, 2010
Messages
1
The easiest way I've found so far: use "CONCATENATE" Excel function, i.e.,

=CONCATENATE( B1, "" )

where B1 is a number.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,883
Messages
5,766,911
Members
425,385
Latest member
djkevnic

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
Top