开发者

Formatting Textbox in VBA 4 place decimal

Is there anyway that you can format a textbox format to have four decimal places at all time? I know how to do it with C# and Visual Basic using a masked textbox, but vba is a bit more challeging due to the lack of function. Any help woul开发者_开发技巧d be greatly appreciated. Thanks

Public Sub UserForm_Initialize()
TextBox6.Text = Format(Number, "###.####")
End Sub


You just have the format string incorrect. It should look like this:

Public Sub UserForm_Initialize()
    TextBox6.Text = Format(Number, "0.0000")
End Sub


Try:

Public Sub UserForm_Initialize()
     TextBox6.Text = Format(Number, "0.0000")
End Sub

Private Sub TextBox6_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If IsNumeric(TextBox6.Value) Then
        TextBox6.Text = Format(TextBox6, "0.0000")
    End If
End Sub

Private Sub TextBox6_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    '// Disregard keys other than 0-9/period/minus sign.
    If Shift Then KeyCode = 0
    Select Case KeyCode
    Case 8, 13, 46, 48 To 57, 96 To 105, 109, 110, 189, 190
    Case Else
        KeyCode = 0
    End Select
End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜