Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 577
Default convert number to text

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default convert number to text

sStr = format(5,"000")

--
Regards,
Tom Ogilvy


"Scott" wrote:

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?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default convert number to text

Sub routine()
Dim n As Integer, s As String
n = 5
s = Format(n, "000")
MsgBox (s)
End Sub
--
Gary''s Student
gsnu200711

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 577
Default convert number to text

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.


"Gary''s Student" wrote:

Sub routine()
Dim n As Integer, s As String
n = 5
s = Format(n, "000")
MsgBox (s)
End Sub
--
Gary''s Student
gsnu200711

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default convert number to 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


--
Regards,
Tom Ogilvy


"Scott" wrote:

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.


"Gary''s Student" wrote:

Sub routine()
Dim n As Integer, s As String
n = 5
s = Format(n, "000")
MsgBox (s)
End Sub
--
Gary''s Student
gsnu200711



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 577
Default convert number to text

It works!

Thank you, Tom.

"Tom Ogilvy" wrote:

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


--
Regards,
Tom Ogilvy


"Scott" wrote:

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.


"Gary''s Student" wrote:

Sub routine()
Dim n As Integer, s As String
n = 5
s = Format(n, "000")
MsgBox (s)
End Sub
--
Gary''s Student
gsnu200711

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default convert number to text

format([a1],"000")

--
Kind regards,

Niek Otten
Microsoft MVP - Excel

"Scott" wrote in message ...
| 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?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert text number to number formate [email protected] Excel Discussion (Misc queries) 2 April 9th 07 10:48 AM
Convert a number formatted as text to a number in a macro MACRE0[_5_] Excel Programming 2 October 22nd 05 02:51 AM
convert text-format number to number in excel 2000%3f Larry Excel Discussion (Misc queries) 1 July 29th 05 08:18 PM
not able to convert text, or graphic number to regular number in e knutsenk Excel Worksheet Functions 1 April 2nd 05 08:41 AM
Convert number in text format to number Cheryl[_3_] Excel Programming 2 May 25th 04 06:51 PM


All times are GMT +1. The time now is 02:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"