CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Oct 2003
    Location
    Athens
    Posts
    231

    How do I set the numberformat of a textbox- VBA/VB6

    Dear All,

    I have the following code which populates a textbox with a value from an excel cell, in this case 2000000. But I want the commas and cannot seem to get them even though the excel cell has the format 2,000,000.


    Please can anyone tell me how to make sure the textbox value has the commas.

    Thanks in advance!

  2. #2
    Join Date
    Dec 2004
    Posts
    423

    Re: How do I set the numberformat of a textbox- VBA/VB6

    You can change the DAtaFormat properties.


    Or you can Format the data going into the textbox
    textbox1.text = FORMAT(Number, "###,###,###.00")

  3. #3
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    516

    Re: How do I set the numberformat of a textbox- VBA/VB6

    You just need to format the value you get from Excel. Excel stores everything as variants, so if there is a number in the cell, it gets a numeric sub-type.
    Code:
    Text1.Text = Format$(Value, "#,###")

  4. #4
    Join Date
    Oct 2003
    Location
    Athens
    Posts
    231

    Re: How do I set the numberformat of a textbox- VBA/VB6

    Many thanks guys...it worked a treat!

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

Featured