Link to home
Start Free TrialLog in
Avatar of Harsh Kumar
Harsh KumarFlag for Denmark

asked on

vba word number formatting a textbox

Hi again experts,

Another quick question, i'm trying to find a way to format a few userform textbox's but no luck its for formatting it incorrect.

this is the code:

Private Sub txtvjhjp_AfterUpdate()

txtvjhjp.Text = Format(txtvjhjp.Value, "#.##0,00")

End Sub

Open in new window


The result is this: 7000,0000
when it should be this: 7.000,00

I'm also looking for a way to do it easier, there is a few textboxes that need this format is there an easier way, like simply right the textbox name on a list and it will put the form in them all, something like this:

Private Sub decimalseparator_AfterUpdate()

Format(value, "#.##0,00")
    .txtvjhjp
    .txtvjhp
    .txtabc
End Sub

Open in new window


no clue if this is possible at all but would make it easier and the code would be more clean i guess :)

thank you in advance
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Harsh Kumar

ASKER

that worked like a charm!! awesome thank you!,

 but how about a code for more textboxes using this format?
Avatar of Rgonzo1971
Rgonzo1971

No easy way that I can think of
You can just select all the textboxes together (using the Ctrl key) then just insert the following in the FORMAT property:
#,##0.00

Ron
You have to make a translation when coding formats in countries where the decimal symbol is a comma and the thousands separator is a period.
IrogSinta - I can't seem to fin that propety, is that in the propeties window?
It's the topmost property in the Format tab of the Property Sheet. If you put #,##0.00 in there it will automatically change to Standard

User generated image
Sadly i think this function is only available in access or so, im try to code this in word vba so its not there.

But thanks!

User generated image