Number format in userform textbox

Atholl

Active Member
Joined
May 19, 2002
Messages
434
Hi everyone,
Can anyone tell me how to control the format of numbers (i.e. amount of decimal places) in a textbox within a userform. The userform seems to ignore the formatting on the worksheet. I assume you can change this within the properties section of the textbox, but I can't seem to find what controls number format.
Cheers,

Atholl
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
It's not that simple. If the user writes in numbers in a different format, how are you going to solve that?

One good way is to use the Format function. See helpfile for info on that.
 
Upvote 0
The thing is, the textboxes I want to format display the outputs of my spreadsheet, so I know approximately the size of the numbers

Best Regards,

Atholl
 
Upvote 0
Then use the Format function:

txtValue = Format(Value, "000.00")

Change the "000.00" to whatever you like. Use *'s and 0's
 
Upvote 0
Does anyone know how to capture a date and time entry in a userform textbox and then when I insert it into a cell value, the value will display as the cell is formatted instead of how the userform formats it?

I have a row of cells formatted like this: d/m "@" hhmm"h"
I can enter a date time combination like this: 28/5 16:00
And Excel makes the call value like this: 28/05/2011 4:00:00 PM
If in the UserForm I use: Format(Me.TextBox1.Value, "d/m \@ hhmm\h")
Excel will make the cell value like this: 28/5 @ 1600h

How can I make the cell value equal the full date time group, yet display the formatted date time group from a userform?

Thanks in advance.
 
Upvote 0
I have tried numerous options. The only way to do it appears to put it in the format that it likes. Then enter the cell and press enter.

However, this code keep looping. Why?

Code:
Private Sub CommandButton4_Click()
num = Range("A50").Value
num = num + num + 5
Cells(4, num).Value = Me.ComboBox4.Value
Cells(6, num).Value = Me.TextBox4.Value
Cells(8, num).Value = Format(Me.TextBox5.Value, "d/mm/yyyy") & " " & Format(Left(Me.TextBox6.Value, 2) & ":" & Right(Me.TextBox6.Value, 2), "h:mm:ss AM/PM")
Cells(8, num).Select
SendKeys "{F2}", True
SendKeys "~", True
End Sub
 
Upvote 0
Sorted...hitting "Enter" from within a UserForm was simply re-igniting the commandbutton...

Is there any way to keep this userform open and sendkeys to the sheet...like:

Sheets("NOV").SendKeys "{F2}" ???
 
Upvote 0
Tobbes,

Using the textbox exit event works for me, as per example below. You obviously need to make sure to code around there being any unexpected exits that may overwrite your desired date capture.


Code:
Private Sub tbxDate_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Sheets("Management").Range("A30").Value = Me.tbxDate.Value
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,167
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top