Option
Explicit
Dim
spinning
As
Boolean
, Min#, Max#, Schrittweite#
Dim
changedByTextbox
As
Boolean
Private
Sub
TextBox1_Exit(
ByVal
Cancel
As
MSForms.ReturnBoolean)
TextBox1 = Format(TextBox1,
"0.000"
)
End
Sub
Private
Sub
UserForm_Initialize()
Schrittweite = 1000
Min = 0
Max = 10
With
SpinButton1
.Min = Min * Schrittweite
.Max = Max * Schrittweite
End
With
End
Sub
Private
Sub
TextBox1_Change()
Dim
Val
Val = TextBox1.Value
If
Not
IsNumeric(Val)
Or
Val < Min
Or
Val > Max
Then
If
Not
Val =
""
And
Not
TextBox1 = 0
Then
TextBox1 = 0
Exit
Sub
End
If
Range(
"C10"
) =
CDbl
(Val)
If
Not
spinning
Then
changedByTextbox =
True
SpinButton1 = Val * Schrittweite
changedByTextbox =
False
End
If
End
Sub
Private
Sub
SpinButton1_Change()
If
Not
changedByTextbox
Then
Dim
Val#
Val = SpinButton1.Value / Schrittweite
spinning =
True
TextBox1 = Format(Val,
"0.000"
)
spinning =
False
Range(
"C10"
) = Val
End
If
End
Sub
Private
Sub
CommandButton1_Click()
TextBox1.Value = Format(Range(
"B3"
).Value,
"0.000"
)
TextBox2.Value = Range(
"B13"
).Value
TextBox3.Value = Range(
"B5"
).Value
TextBox4.Value = Range(
"B15"
).Value
TextBox5.Value = Range(
"B11"
).Value
End
Sub
Private
Sub
TextBox2_KeyPress(
ByVal
KeyAscii
As
MSForms.ReturnInteger)
Select
Case
KeyAscii
Case
48
To
57
Case
44, 46
KeyAscii = 44
If
InStr(1, TextBox2.Text,
","
)
Then
KeyAscii = 0
Case
Else
: KeyAscii = 0
End
Select
End
Sub