Consulting

Results 1 to 4 of 4

Thread: Solved: change variable ; from 2000000 to $2,000,000

  1. #1

    Question Solved: change variable ; from 2000000 to $2,000,000

    Hi All,

    I have a variable (variable_1) that has the value 2000000
    This has come from an excel cell, containing the value 2000000

    Now, I want to use the variable as a string, but in the format of $2,000,000


    How would I convert the variable value to $2,000,000
    Or would I need variable_2 based on variable_1
    Not sure how to procede on this, would anyone offer a way forward.

  2. #2

    Arrow

    SOLVED....

    it's
    Variable_2 = Format(Variable_1, "Currency")

  3. #3
    VBAX Mentor
    Joined
    Jun 2004
    Posts
    363
    Location
    You could declare your variable as a Variant and do something like this:

    [vba]Dim variable_1 as Variant
    'some code
    variable_1 = Format(variable_1, "$0,000")[/vba]
    I wouldn't recommend using this method. I would either use two variables or convert the variable_1 to the string when I was ready to use it.

    [vba]Dim Variable_1 as Double, Variable_2 as String
    'other code
    Variable_2=Format(Variable_1,"$0,000")[/vba]

  4. #4

    Thumbs up

    Yes, I prefer to use 2 variables, although a little longer.

    I just noticed that "currency" adds the .00 to the end so I get $2,000,000.00

    I think your solution will get rid of the .00 at the end.
    Thanks.

Posting Permissions

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