Použite výpočet inak. Mod vo VBA nie je to isté ako MOD v Exceli. Môžete použiť aj vyremované vypínanie Events
'Dim DisableEvent As Boolean
Private Sub TextBox1_Change()
'If DisableEvent Then Exit Sub
Zmena
End Sub
Private Sub TextBox2_Change()
'If DisableEvent Then Exit Sub
Zmena
End Sub
Private Sub TextBox3_Change()
'If DisableEvent Then Exit Sub
Zmena
End Sub
Sub Zmena()
Dim zac As Date, kon As Date
On Error Resume Next
zac = TimeValue(Me.TextBox1.Value)
kon = TimeValue(Me.TextBox2.Value)
Me.TextBox4.Value = MODX(kon - zac, 1) * 24 - (Me.TextBox3.Value / 60)
If Err.Number <> 0 Then Me.TextBox4.Text = ""
End Sub
Private Sub UserForm_Initialize()
'DisableEvent = True
Me.TextBox1.Value = "22:00"
Me.TextBox2.Value = "06:00"
'DisableEvent = False
Me.TextBox3.Value = "30"
End Sub
Function MODX(Cislo As Double, Del As Integer) As Double
MODX = Cislo - Del * Int(Cislo / Del)
End Function
'Dim DisableEvent As Boolean
Private Sub TextBox1_Change()
'If DisableEvent Then Exit Sub
Zmena
End Sub
Private Sub TextBox2_Change()
'If DisableEvent Then Exit Sub
Zmena
End Sub
Private Sub TextBox3_Change()
'If DisableEvent Then Exit Sub
Zmena
End Sub
Sub Zmena()
Dim zac As Date, kon As Date
On Error Resume Next
zac = TimeValue(Me.TextBox1.Value)
kon = TimeValue(Me.TextBox2.Value)
Me.TextBox4.Value = MODX(kon - zac, 1) * 24 - (Me.TextBox3.Value / 60)
If Err.Number <> 0 Then Me.TextBox4.Text = ""
End Sub
Private Sub UserForm_Initialize()
'DisableEvent = True
Me.TextBox1.Value = "22:00"
Me.TextBox2.Value = "06:00"
'DisableEvent = False
Me.TextBox3.Value = "30"
End Sub
Function MODX(Cislo As Double, Del As Integer) As Double
MODX = Cislo - Del * Int(Cislo / Del)
End Function
Příloha: 52324_52319_vba-cas.zip (18kB, staženo 9x)
citovat