convert number to text

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

how to convert a number to text in vba, e.g. showing 5 as "005". I can do it
on spreadsheet with a function like '=Text(A1,"000")'. can it be done in vba?
 
format([a1],"000")

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

| how to convert a number to text in vba, e.g. showing 5 as "005". I can do it
| on spreadsheet with a function like '=Text(A1,"000")'. can it be done in vba?
 
Here are my codes:

Dim i As Long, lastrow As Long
lastrow = Range("A1").CurrentRegion.Rows.Count
For i = 1 To lastrow
Cells(i, 8) = Format(Cells(i, 6), "000")
Next

I still got numbers, not text.
 
Dim i As Long, lastrow As Long
lastrow = Range("A1").CurrentRegion.Rows.Count
For i = 1 To lastrow
Cells(i, 8) = "'" & Format(Cells(i, 6), "000")
Next
 
It works!

Thank you, Tom.

Tom Ogilvy said:
Dim i As Long, lastrow As Long
lastrow = Range("A1").CurrentRegion.Rows.Count
For i = 1 To lastrow
Cells(i, 8) = "'" & Format(Cells(i, 6), "000")
Next
 
Back
Top