ich habe eine Userform mit 24 TextBoxen, in de ersten Spalte prüfe ich ob die Zelle der erste eines Monats ist, dann soll die ganze Zeile bis Spalte X eine fette Schriftart haben.
Das ganze funktioniert auch, aber das speichern dauert einfach zu lang.
Kann mann das ganze beschleunigen oder optimieren also den Code kürzer schreiben.
Im Augenblick sieht das ganze so aus:
Währe für eine Lösung dankbar.
Gruß
Andi
Private Sub CommandButton3_Click()
Dim lZeile As Long
Dim i As Integer
Application.DisplayAlerts = False
If ListBox1.ListIndex = -1 Then Exit Sub
If Trim(CStr(TextBox1.Text)) = "" Then
Exit Sub
End If
lZeile = 4
Do While Trim(CStr(Tabelle20.Cells(lZeile, 1).Value)) ""
If ListBox1.Text = Trim(CStr(Tabelle20.Cells(lZeile, 1).Value)) Then
If IsDate(TextBox1.Text) Then .Cells(lZeile, 1).Value = Trim(CDate(TextBox1. _
Text))
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 1).Font.Bold = _
True
If IsNumeric(TextBox2.Text) Then .Cells(lZeile, 2).Value = CDbl(TextBox2.Text)
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 2).Font.Bold = _
True
TextBox3.Value = .Cells(lZeile, 2).Value - .Cells(lZeile - 1, 2).Value
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 3).Font.Bold = _
True
If IsNumeric(TextBox3.Text) Then .Cells(lZeile, 3).Value = CDbl(TextBox3.Text)
.Cells(lZeile, 4).Value = Format(TextBox4.Text, "0 °C")
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 4).Font.Bold = _
True
If IsNumeric(TextBox5.Text) Then .Cells(lZeile, 5).Value = CDbl(TextBox5.Text)
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 5).Font.Bold = _
True
TextBox6.Value = .Cells(lZeile, 5).Value - .Cells(lZeile - 1, 5).Value
If IsNumeric(TextBox6.Text) Then .Cells(lZeile, 6).Value = CDbl(TextBox6.Text)
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 6).Font.Bold = _
True
.Cells(lZeile, 7).Value = Format(TextBox7.Text, "0 °C")
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 7).Font.Bold = True
If IsNumeric(TextBox8.Text) Then .Cells(lZeile, 8).Value = CDbl(TextBox8.Text)
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 8).Font.Bold = _
True
TextBox9.Value = .Cells(lZeile, 8).Value - .Cells(lZeile - 1, 8).Value
If IsNumeric(TextBox9.Text) Then .Cells(lZeile, 9).Value = CDbl(TextBox9.Text)
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 9).Font.Bold = _
True
.Cells(lZeile, 10).Value = Format(TextBox10.Text, "0 °C")
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 10).Font.Bold = _
True
If IsNumeric(TextBox11.Text) Then .Cells(lZeile, 11).Value = CDbl(TextBox11. _
Text)
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 11).Font.Bold = _
True
TextBox12.Value = .Cells(lZeile, 11).Value - .Cells(lZeile - 1, 11).Value
If IsNumeric(TextBox12.Text) Then .Cells(lZeile, 12).Value = CDbl(TextBox12. _
Text)
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 12).Font.Bold = _
True
.Cells(lZeile, 13).Value = Format(TextBox13.Text, "0 °C")
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 13).Font.Bold = _
True
If IsNumeric(TextBox14.Text) Then .Cells(lZeile, 14).Value = CDbl(TextBox14. _
Text)
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 14).Font.Bold = _
True
TextBox15.Value = .Cells(lZeile, 14).Value - .Cells(lZeile - 1, 14).Value
If IsNumeric(TextBox15.Text) Then .Cells(lZeile, 15).Value = CDbl(TextBox15. _
Text)
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 15).Font.Bold = _
True
.Cells(lZeile, 16).Value = Format(TextBox16.Text, "0 °C")
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 16).Font.Bold = _
True
If IsNumeric(TextBox17.Text) Then .Cells(lZeile, 17).Value = CDbl(TextBox17. _
Text)
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 17).Font.Bold = _
True
TextBox18.Value = .Cells(lZeile, 17).Value - .Cells(lZeile - 1, 17).Value
If IsNumeric(TextBox18.Text) Then .Cells(lZeile, 18).Value = CDbl(TextBox18. _
Text)
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 18).Font.Bold = _
True
.Cells(lZeile, 19).Value = Format(TextBox19.Text, "0 °C")
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 19).Font.Bold = _
True
If IsNumeric(TextBox20.Text) Then .Cells(lZeile, 20).Value = CDbl(TextBox20. _
Text)
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 20).Font.Bold = _
True
If IsNumeric(TextBox21.Text) Then .Cells(lZeile, 21).Value = CDbl(TextBox21. _
Text)
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 21).Font.Bold = _
True
TextBox22.Value = .Cells(lZeile, 21).Value - .Cells(lZeile - 1, 21).Value
If IsNumeric(TextBox22.Text) Then .Cells(lZeile, 22).Value = TextBox22.Text
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 22).Font.Bold = _
True
.Cells(lZeile, 23).Value = Format(TextBox23.Text, "0 °C")
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 23).Font.Bold = _
True
If IsNumeric(TextBox24.Text) Then .Cells(lZeile, 24).Value = CDbl(TextBox24. _
Text)
If pruefung_Monatserster(TextBox1.Text) Then .Cells(lZeile, 24).Font.Bold = _
True
End With
If ListBox1.Text Trim(CStr(TextBox1.Text)) Then
Call UserForm_Initialize
If ListBox1.ListCount > 0 Then ListBox1.ListIndex = 0
End If
Exit Do
End If
lZeile = lZeile + 1 'Nächste Zeile bearbeiten
Loop
Fehler:
Application.DisplayAlerts = True
End Sub