无论如何,您可以将文本框格式格式化为始终保留四位小数?我知道如何使用 C# 和 Visual Basic 使用蒙版文本框来做到这一点,但由于缺乏功能,vba 更具挑战性。任何帮助将不胜感激。谢谢
Public Sub UserForm_Initialize()
TextBox6.Text = Format(Number, "###.####")
End Sub
您只是格式字符串不正确。它应该如下所示:
Public Sub UserForm_Initialize()
TextBox6.Text = Format(Number, "0.0000")
End Sub
尝试:
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