Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert a number into a string 3

Status
Not open for further replies.

JensKKK

Technical User
May 8, 2007
119
GB
I think that is such a simple question, but I can't find any command in VBA to convert a number such as 1204 into the corresponding string "1204".

Any suggestions at this point

If have tried to read the number out of a cell and assign it to a string, but that does not compatible with creating hyperlinks.

This is the code example. the code works perfectly when the cell content is a string , but it crashes when it is a number.

'Gen hyperlink
part1 = Sheets("3d rotate").Cells(13999 + i, 15) & Sheets("3d rotate").Cells(13999 + i, 11)
part2 = Sheets("3d rotate").Cells(13999 + i, 11)
Sheets("content information").Select
Sheets("content information").Cells(6 + i, 4).Select
Sheets("Content Information").Hyperlinks.Add _
Anchor:=Selection, Address:=part1, TextToDisplay:=part2
 
have a look at cstr,

also the numberformat property

Code:
Sub chance()
Dim intX As Integer
intX = 1203

'use the cstr function
Sheet1.Cells(1, 1) = CStr(intX)

'or set the format of the cell before populating

Sheet1.Cells(1, 2).NumberFormat = "@"
Sheet1.Cells(1, 2) = intX

End Sub

Chance,

Filmmaker, gentleman and ROMAN!
 
Thanks Chance.

Code works brillianttly.

 
Hi JensKKK,
Try the folling:
Which part (1 or 2) contains the number?
For example, part1 contains the number which we want to convert to a string...change that part of the code to:
part1 = cStr(Sheets("3d rotate").Cells(13999 + i, 15) & Sheets("3d rotate").Cells(13999 + i, 11))

The function you're looking for is cStr()

Let us know your findings..



Greetings,
Michel Scheffer
The Netherlands
 
A simpler way ?
...
Anchor:=Selection, Address:=part1 & "", TextToDisplay:=part2 & ""

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks Michel

cstr works fine for me.
 
PHV your method works as well.

Thanks for sharing your thoughts with me.

Jens
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top