ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   format validation in UserForm textboxes (https://www.excelbanter.com/excel-programming/382407-format-validation-userform-textboxes.html)

Soultek

format validation in UserForm textboxes
 
Hi ,

can any one help me ? I had created the following Userform , with several
textboxes that users would have to key in a $ value.

I managed to get the textbox to display as $0 with the following code

Private Sub txtUT_Change()
Me.txtUT.Value = Format(Me.txtUT.Value, "$###,##0")
End Sub

however, users still can enter text data , which I want to prevent them from
doing so.



Tom Ogilvy

format validation in UserForm textboxes
 
code previously posted by Harald Staff,

Private Sub TextBox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
DecSep = Mid$(Format(1.5, "0.0"), 2, 1)
Select Case KeyAscii
Case 8 To 10, 13, 27 'Control characters
Case 44, 46
If Me.LDecimals 0 And InStr(TextBox.Text, DecSep) = 0 Then
KeyAscii = Asc(DecSep)
Else
Beep
KeyAscii = 0
End If
Case 45
If Me.Negatives And TextBox.SelStart = 0 Then
Else
Beep
KeyAscii = 0
End If
Case 48 To 57 'numbers
Case Else 'Discard anything else
Beep
KeyAscii = 0
End Select
End Sub


--
Regards,
Tom Ogilvy

"Soultek" wrote:

Hi ,

can any one help me ? I had created the following Userform , with several
textboxes that users would have to key in a $ value.

I managed to get the textbox to display as $0 with the following code

Private Sub txtUT_Change()
Me.txtUT.Value = Format(Me.txtUT.Value, "$###,##0")
End Sub

however, users still can enter text data , which I want to prevent them from
doing so.




All times are GMT +1. The time now is 12:22 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com