Number Format in VBA

  • Thread starter Thread starter PhilM
  • Start date Start date
P

PhilM

How to a force VBA to show an integer as a fixed number of digits? eg
display 240 as 0000240
 
Set the format (Format>Cells>Custom) to 0000000

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Hi Phil

Assuming you want your variable myVar to hold this value:

myVar = Format(240,"0000000")

Note that this is held as a string value. If you simply want to
display 240 in your sheet in the desired format, then you need to set
the number format of the cell that holds the value:

Range("A1").Value = 240
Range("A1").NumberFormat = "0000000"

Hope this helps!

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top