Avatar of Adil Kh
Adil Kh
 asked on

Number format in Textbox

Good morning,

In my textbox4 i succed to give a format to the number like 1 254 254  but when i apply it to my textbox3 It doesn't work. I want it with decimals in my textbox 3

Thank you
Draft.xlsm
VBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Subodh Tiwari (Neeraj)

8/22/2022 - Mon
SOLUTION
Subodh Tiwari (Neeraj)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Roy Cox

You need to use the code  for each textbox as given in your previous post. e.g
Private Sub TextBox3_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
     
     ' '///Numeric values only
    Select Case KeyAscii
    Case 46 ' period
    Case 48 To 57 ' 0 to 9
    Case 43 ' +
    Case 45 ' -
    Case 49 ' backspace
    Case Else
        KeyAscii = vbNull
    End Select
     
End Sub

Open in new window


And as JKP said do not use the KeyDown event from the code and only use the KeyPress event.
Fabrice Lambert

Side note:
- Give meaningfull names to your forms, controls and variables, so we (and later, you) can understand better what you are doing.
For instance, UserForm1, UserForm2 ect .. ComboBox1, TextBox1 ect ... are not meaningfull.

- Unless you have a very valid reason, do not use global variables. It is usually a sign of bad design.
As it stand, your workbook don't need any.

- Avoid using objects such as ActiveWorkbook, ActiveSheet, ActiveCell, ActiveChart, Selection (the worst one), the global Workbooks, Sheets, Cells, Range collections, because these are user dependant and chaotic objects, as a developper, you don't want to use chaotic objects.

- Within your forms, you don't need to constantly use the "Me" keyword. Forms are class, and each instance know itself.

- Discipline never hurt, use Option Explicit at the top of all your modules.

- Write error handlers.
Adil Kh

ASKER
@Subodh Tiwari (Neeraj) Yes Userform1 In texbox4 number as 1 000 000 no decimals are allowded. In textbox3 decimals are allowded but in this format 1 000 000,00 not like 1000000 Do you get what I mean?

@Roy Cox Thank you but when i applied it in textbox3 it accept no limit points (.) It should be only one point (.)

Thank you
Draft.xlsm
Your help has saved me hundreds of hours of internet surfing.
fblack61
Adil Kh

ASKER
Thank you @Fabrice Lambert It is helpful as i am just a beginner I should learn.
Is there a document or website you recomand me to visit in order to develop those fondamentals?

Thank you
SOLUTION
Fabrice Lambert

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Roy Cox

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Adil Kh

ASKER
Hi Fabrice,

I have an error when i apply your code

Please see the error attached
Pic.png
Adil Kh

ASKER
Hi Roy Rox,

Because I have a french Excel that's why we use . instead of , and vice versa

Thank you for the website helpful and interesting.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Adil Kh

ASKER
Hi Subodh Tiwari (Neeraj)

Thank you for the file but there is no format like 1 000 000.00 in txbox 3 only like 1000000.00

Thank you
Fabrice Lambert

Hi Fabrice,

 I have an error when i apply your code
You did not follow my instructions !!!!!
Write this in a standard module
SOLUTION
Roy Cox

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Adil Kh

ASKER
Thank you
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Roy Cox

Pleased to help
Subodh Tiwari (Neeraj)

You're welcome Adil!