ich erarbeite gerade eine UserForm, die eine Meldung aufbringen soll, falls ein Enddatum ausgewählt wird, das hinter dem Anfangsdatum liegt. Dies erfolgt auch, allerdings erscheint die MsgBox nach einem Klick auf Okay noch zwei weitere Male. Wie kann ich das verhindern?
Zusatzfrage: Kann ich das ausgewählte Datum auch ins Format dd/mm/yyyy bringen statt wie bisher dd-mm-yyyy?
Der aktuelle Code für die Änderung der ComboBox mit Enddatum ist:
Private Sub ComboBox2_Change()
CommandButton1.Enabled = True
ComboBox2.Text = Format(ComboBox2.Value, "dd-mm-yyyy")
If ComboBox1.Value > ComboBox2.Value Then
CommandButton1.Enabled = False
MsgBox ("The final date is before the initial one.")
End If
End Sub
Weiter unten findet ihr die übrigen UserForm Subs.
Vielen Dank im Voraus für Eure Hilfe!
-------- WEITERE USERFORM SUBS ----------------
Dim vdateinitiale As Date
Dim vdatefinale As Date
Dim vperf1 As Variant
Dim vperf2 As Variant
Private Sub ComboBox1_Change()
CommandButton1.Enabled = True
ComboBox1.Text = Format(ComboBox1.Value, "dd-mm-yyyy")
End Sub
Private Sub ComboBox4_Change()
CommandButton1.Enabled = True
If ComboBox4.Text = ComboBox3.Text Then
MsgBox ("Select another currency please.")
CommandButton1.Enabled = False
End If
End Sub
Private Sub CommandButton1_Click()
Worksheets(3).Activate
vdateinitiale = ComboBox1.Value
vdatefinale = ComboBox2.Value
Range("B2").Value = vdateinitiale
Range("B3").Value = vdatefinale
Range("B5").Value = ComboBox3.Value
Range("B6").Value = ComboBox4.Value
Range("d2").FormulaLocal = "=Match(b2;Date!a2:a3059;0)"
Range("d3").FormulaLocal = "=Match(b3;Date!a2:a3059;0)"
Range("d5").FormulaLocal = "=Match(b5;Date!b1:p1;0)"
Range("d6").FormulaLocal = "=Match(b6;Date!b1:p1;0)"
Range("D8").FormulaLocal = "=index(Date!b2:r3059;d2;d5)"
Range("E8").FormulaLocal = "=index(Date!b2:r3059;d3;d5)"
Range("D9").FormulaLocal = "=index(Date!b2:r3059;d2;d6)"
Range("E9").FormulaLocal = "=index(Date!b2:r3059;d3;d6)"
vval1 = Range("D8").Value
vval2 = Range("E8").Value
Range("B8").Value = (vval2 - vval1) / vval1
vval3 = Range("D9").Value
vval4 = Range("E9").Value
Range("B9").Value = (vval4 - vval3) / vval3
'Start of our code
Call StDevCorr
Unload UserForm1
End Sub
Private Sub CommandButton2_Click()
Unload UserForm1
End Sub