Results 1 to 3 of 3

Thread: format nember in vba for excel

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    format nember in vba for excel

    I need to format a my number in:

    for example:
    Myvar=1 in MyNewvar=1,00
    Myvar=1,5 in MyNewvar=1,50
    ...

    In all case of Myvar use always two decimal after the decimal point, even if the number is an integer

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: format nember in vba for excel

    Thread moved from the 'Database Development' forum to the 'Office Development/VBA' forum

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: format nember in vba for excel

    try like
    Code:
    mynewvar = format(myvar, "Standard")
    though normal procedure is to keep numbers unformatted in variables and only formatting when displaying to user
    as a formatted number is a string, it is more difficult to do any calculations
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width